我试图通过按下按钮来打开一个活动,当我按下按钮时,activty 包含 5 个编辑文本和 1 个微调器,它不幸地显示正在关闭 login.apk。
这是注册.java的代码片段
public class Registration extends Activity {
EditText name,password,email,dob,design,cpassword;
Button submit,cancel;
Spinner gender;
SQLiteDatabase db;
String Gen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
name=(EditText)findViewById(R.id.editText1);
email=(EditText) findViewById(R.id.editText2);
gender=(Spinner) findViewById(R.id.spinner1);
dob=(EditText) findViewById(R.id.editText3);
design=(EditText) findViewById(R.id.editText4);
password=(EditText) findViewById(R.id.editText5);
cpassword=(EditText) findViewById(R.id.editText6);
db=openOrCreateDatabase("MobWalletDB",MODE_PRIVATE, null);
List<String> list=new ArrayList<String>();
list.add("Male");
list.add("Female");
ArrayAdapter<String> mAdapter= new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
gender.setAdapter(mAdapter);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
MODELUserData userGivenDataObject=new MODELUserData(name.getText().toString()
,email.getText().toString(),Gen,dob.getText().toString(),design.getText().toString(),password.getText().toString());
if(QUERYUserReg.registerUser(db, userGivenDataObject)){
Toast.makeText(getBaseContext(), "User Registered!!!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(Registration.this,Login.class));
}else
Toast.makeText(getBaseContext(), "Registration Failure!!!", Toast.LENGTH_SHORT).show();
}
});
gender.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int in,
long lg) {
// TODO Auto-generated method stub
Gen=parent.getItemAtPosition(in).toString();
}
});
}
}
并且 Logcat 显示以下错误
05-29 07:22:48.331: E/AndroidRuntime(13236): FATAL EXCEPTION: main05-29 07:22:48.331:
E/AndroidRuntime(13236): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.login/com.example.login.Registration}: java.lang.NullPointerException
...
...
05-29 07:22:48.331: E/AndroidRuntime(13236): Caused by: java.lang.NullPointerException
05-29 07:22:48.331: E/AndroidRuntime(13236): at com.example.login.Registration.onCreate(Registration.java:49)
05-29 07:22:48.331: E/AndroidRuntime(13236): at android.app.Activity.performCreate(Activity.java:5104)
05-29 07:22:48.331: E/AndroidRuntime(13236): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-29 07:22:48.331: E/AndroidRuntime(13236): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-29 07:22:48.331: E/AndroidRuntime(13236): ... 11 more
请告诉我错误是什么?
提前致谢