当我单击一个按钮将我带到另一个页面时,我的程序崩溃了。我的 OnClickListener 似乎是正确的,但我知道我错过了一些东西。谁能看到我哪里出错了?
错误:
08-20 13:40:30.622: E/AndroidRuntime(1026): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.LoginScr.Example/com.LoginScr.Example.CredentialsActivity}: java.lang.NullPointerException
从用于调用第二个活动的主要活动:
lsRegstr.setOnClickListener (new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(LoginScrExample.this, CredentialsActivity.class);
startActivity(i);
}
凭证活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
rName = (EditText)findViewById(R.id.reg_uname);
rCode= (EditText)findViewById(R.id.reg_pswd);
bReg = (Button) findViewById(R.id.reg_button);
bReg.setOnClickListener(this);
bRtn = (Button) findViewById(R.id.rtn_button);
bRtn.setOnClickListener(this);
Bundle RegBundle = getIntent().getExtras();
bundleRegName = RegBundle.getString(rUsername);
bundleRegCode = RegBundle.getString(rPasscode);
rName.setText(bundleRegName);
rCode.setText(bundleRegCode);
}
@Override
public void onClick (View v) {
rUsername = rName.getText().toString();
rPasscode = rCode.getText().toString();
RegDetails regDetails = new RegDetails();
regDetails.setlName(bundleRegName);
regDetails.setlCode(bundleRegCode);
if(v.getId()==R.id.rtn_button){
finish();
}else if(v.getId()==R.id.reg_button){
insertCredentials(regDetails);
}
}
private void insertCredentials(RegDetails regDetails){
LoginDB androidOpenDBHelper = new LoginDB(this);
SQLiteDatabase sqliteDB = androidOpenDBHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(LoginDB.COLUMN_NAME_USERNAME, rUsername);
contentValues.put(LoginDB.COLUMN_NAME_PASSWORD, rPasscode);
String[] whereClauseArgument = new String[1];
whereClauseArgument[0] = regDetails.getlName();
System.out.println(" Credentials Saved!" + whereClauseArgument[0]);
sqliteDB.close();
finish();
}
}