将数据添加到数据库时出现空指针异常。我的java文件粘贴在这里,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
findViewById();
btnSave.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(!etPassword.getText().toString().equals(etConfPassword.getText().toString())){
displayToast("Please confirm Password");
}else if(etUserName.getText().toString().equals("")){
displayToast("Please enter Login ID");
}else if(etPassword.getText().toString().equals("")){
displayToast("Please enter Password");
}else if(isExisting(etFirstName.getText().toString(), "loginId", "UserDetails")){
displayToast("This User already exist");
}else{
handleDB();
finish();
startActivity(new Intent(getApplicationContext(), Replay.class));
}
}
});
}
private void handleDB() {
try {
ContentValues contentValues = new ContentValues();
contentValues.put("firstName", etFirstName.getText().toString());
contentValues.put("lastName", etLastName.getText().toString());
contentValues.put("loginId", etUserName.getText().toString());
contentValues.put("password", etPassword.getText().toString());
contentValues.put("cofmPassword", etConfPassword.getText().toString());
contentValues.put("emailAddress", etEmailAddress.getText().toString());
Replay.database.insert("UserDetails", null, contentValues);
} catch(SQLiteException se ){
Log.e(getClass().getSimpleName(), "Could not create or Open the database");}}
private void displayToast(String msg){
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
}
private void findViewById(){
etFirstName = (EditText) findViewById(R.id.FName);
etLastName = (EditText) findViewById(R.id.LName);
etUserName = (EditText) findViewById(R.id.LoginId);
etPassword = (EditText) findViewById(R.id.Password);
etConfPassword = (EditText) findViewById(R.id.ConfPassword);
etEmailAddress = (EditText) findViewById(R.id.Email);
btnSave = (Button)findViewById(R.id.btnSave);
}};
错误日志是
10-15 08:51:55.932: E/AndroidRuntime(606): FATAL EXCEPTION: main
10-15 08:51:55.932: E/AndroidRuntime(606): java.lang.NullPointerException
10-15 08:51:55.932: E/AndroidRuntime(606): at com.GenioCode.replay.Register$1.onClick(Register.java:38)
10-15 08:51:55.932: E/AndroidRuntime(606): at android.view.View.performClick(View.java:4204)
10-15 08:51:55.932: E/AndroidRuntime(606): at android.view.View$PerformClick.run(View.java:17355)
编译数据库创建后没有任何内容。请帮我找出错误..