填写登录信息后,我无法转到下一页。不知道为什么?
public class SignUP extends Activity {
EditText editTextUserName, editTextPassword, editTextConfirmPassword;
Button btnCreateAccount;
DataBaseAdapter loginDataBaseAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reg);
// get Instance of Database Adapter
loginDataBaseAdapter = new DataBaseAdapter(this);
loginDataBaseAdapter = loginDataBaseAdapter.open();
// Get Refferences of Views
editTextUserName = (EditText)findViewById(R.id.editTextUserName);
editTextPassword = (EditText)findViewById(R.id.editTextPassword);
btnCreateAccount = (Button)findViewById(R.id.buttonCreateAccount);
btnCreateAccount.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String userName = editTextUserName.getText().toString();
String password = editTextPassword.getText().toString();
String confirmPassword = editTextConfirmPassword.getText().toString();
// check if any of the fields are vaccant
if (userName.equals("") || password.equals("") || confirmPassword.equals("")) {
Toast.makeText(getApplicationContext(), "Field Vaccant", Toast.LENGTH_LONG).show();
return;
}
// check if both password matches
if (!password.equals(confirmPassword)) {
Toast.makeText(getApplicationContext(), "Password Does Not Matches", Toast.LENGTH_LONG).show();
return;
}
else {
// Save the Data in Database
loginDataBaseAdapter.insertEntry(userName, password);
Toast.makeText(getApplicationContext(), "Account Successfully Created ", Toast.LENGTH_LONG).show();
Intent menu = new Intent(getApplicationContext(), Menu.class);
startActivity(menu);
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
loginDataBaseAdapter.close();
}
}
logcat的:
08-13 15:09:37.476: E/AndroidRuntime(1113): FATAL EXCEPTION: main
08-13 15:09:37.476: E/AndroidRuntime(1113): Process: com.example.takeit, PID: 1113
08-13 15:09:37.476: E/AndroidRuntime(1113): java.lang.NullPointerException
08-13 15:09:37.476: E/AndroidRuntime(1113): at com.example.takeit.SignUP$1.onClick(SignUP.java:46)
08-13 15:09:37.476: E/AndroidRuntime(1113): at android.view.View.performClick(View.java:4438)
08-13 15:09:37.476: E/AndroidRuntime(1113): at android.view.View$PerformClick.run(View.java:18422)
08-13 15:09:37.476: E/AndroidRuntime(1113): at android.os.Handler.handleCallback(Handler.java:733)
08-13 15:09:37.476: E/AndroidRuntime(1113): at android.os.Handler.dispatchMessage(Handler.java:95)
08-13 15:09:37.476: E/AndroidRuntime(1113): at android.os.Looper.loop(Looper.java:136)
08-13 15:09:37.476: E/AndroidRuntime(1113): at android.app.ActivityThread.main(ActivityThread.java:5017)
08-13 15:09:37.476: E/AndroidRuntime(1113): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 15:09:37.476: E/AndroidRuntime(1113): at java.lang.reflect.Method.invoke(Method.java:515)
08-13 15:09:37.476: E/AndroidRuntime(1113): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-13 15:09:37.476: E/AndroidRuntime(1113): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-13 15:09:37.476: E/AndroidRuntime(1113): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:4)
您忘记初始化editTextConfirmPassword
,因此也要初始化:
editTextConfirmPassword = (EditText)findViewById(R.id.editTextConfirmPassword);