使用parse.com数据库存储数据的Android代码有什么问题

使用parse.com数据库存储数据的Android代码有什么问题,android,parse-platform,Android,Parse Platform,我得到了这个错误: 进程:com.blooddata.lemuriadigitallab.blooddata,PID:26845 java.lang.NullPointerException:尝试在null上调用虚拟方法“android.text.Editable android.widget.EditText.getText()” 对象引用 位于com.blooddata.lemuriadigitallab.blooddata.Register$1.onClick(Register.java:

我得到了这个错误:

进程:com.blooddata.lemuriadigitallab.blooddata,PID:26845 java.lang.NullPointerException:尝试在null上调用虚拟方法“android.text.Editable android.widget.EditText.getText()” 对象引用 位于com.blooddata.lemuriadigitallab.blooddata.Register$1.onClick(Register.java:43) 在android.view.view.performClick上(view.java:5181) 在android.view.view$PerformClick.run(view.java:20887) 位于android.os.Handler.handleCallback(Handler.java:739) 位于android.os.Handler.dispatchMessage(Handler.java:95) 位于android.os.Looper.loop(Looper.java:145) 位于android.app.ActivityThread.main(ActivityThread.java:5942) 位于java.lang.reflect.Method.invoke(本机方法) 位于java.lang.reflect.Method.invoke(Method.java:372) 在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:1400) 位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

初始化“mobile”
EditText
变量

从此处引发NullPointerException:

String nametxt;
String bloodtxt;
String agetxt;
String mobiletxt;
Button register;
EditText name;
EditText age;
EditText blood;
EditText mobile;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);
    name = (EditText) findViewById(R.id.name);
    age = (EditText) findViewById(R.id.age);
    blood = (EditText)findViewById(R.id.blood);
    age = (EditText)findViewById(R.id.age);
    register =(Button)findViewById(R.id.register);
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nametxt = name.getText().toString();
            agetxt = age.getText().toString();
            bloodtxt = blood.getText().toString();//logcat pointing exception here//
            mobiletxt = mobile.getText().toString();
            if (nametxt.equals("") && agetxt.equals("")) {
                Toast.makeText(getApplicationContext(),
                        "Please complete the sign up form",
                        Toast.LENGTH_LONG).show();
            }
            else
            {
                ParseUser user = new ParseUser();
                user.setUsername(nametxt);
                user.setPassword(agetxt);
                user.put("blood", bloodtxt);
                user.put("Mobile",mobiletxt);
                user.signUpInBackground(new SignUpCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e == null) {
                            Toast.makeText(getApplicationContext(), "Succesfully registered", Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(), "hey %d you are already registered in blood database.." + nametxt, Toast.LENGTH_LONG).show();


                        }
                    }
                });
            }

        }
    });

}
初始化“mobile”
EditText
变量

从此处引发NullPointerException:

String nametxt;
String bloodtxt;
String agetxt;
String mobiletxt;
Button register;
EditText name;
EditText age;
EditText blood;
EditText mobile;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);
    name = (EditText) findViewById(R.id.name);
    age = (EditText) findViewById(R.id.age);
    blood = (EditText)findViewById(R.id.blood);
    age = (EditText)findViewById(R.id.age);
    register =(Button)findViewById(R.id.register);
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nametxt = name.getText().toString();
            agetxt = age.getText().toString();
            bloodtxt = blood.getText().toString();//logcat pointing exception here//
            mobiletxt = mobile.getText().toString();
            if (nametxt.equals("") && agetxt.equals("")) {
                Toast.makeText(getApplicationContext(),
                        "Please complete the sign up form",
                        Toast.LENGTH_LONG).show();
            }
            else
            {
                ParseUser user = new ParseUser();
                user.setUsername(nametxt);
                user.setPassword(agetxt);
                user.put("blood", bloodtxt);
                user.put("Mobile",mobiletxt);
                user.signUpInBackground(new SignUpCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e == null) {
                            Toast.makeText(getApplicationContext(), "Succesfully registered", Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(), "hey %d you are already registered in blood database.." + nametxt, Toast.LENGTH_LONG).show();


                        }
                    }
                });
            }

        }
    });

}
您正在初始化“年龄”两次:

因此,这里:

name = (EditText) findViewById(R.id.name);
age = (EditText) findViewById(R.id.age);
blood = (EditText)findViewById(R.id.blood);
age = (EditText)findViewById(R.id.age);
你得到一个空指针

相反,其中一个应该是“移动的”

您正在初始化“年龄”两次:

因此,这里:

name = (EditText) findViewById(R.id.name);
age = (EditText) findViewById(R.id.age);
blood = (EditText)findViewById(R.id.blood);
age = (EditText)findViewById(R.id.age);
你得到一个空指针

相反,其中一个应该是“移动的”


哪一行出现错误?一个edittext字段似乎为空。id错误或不存在。哪一行出现错误?一个edittext字段似乎为空。id错误或不存在
name = (EditText) findViewById(R.id.name);
age = (EditText) findViewById(R.id.age);
blood = (EditText)findViewById(R.id.blood);
mobile = (EditText)findViewById(R.id.mobile);