0

I am trying to open an activity by pressing button activty contains 5 Edit-texts and 1 spinner when I press button it show unfortunately closing login.apk.

here is the code snippet of registartion .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();
        }
    });

}

}

and the Logcat shows the following errors

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

please tell me whats the error?
thanks in advance

4
  • 3
    post Registration.onCreate Commented May 29, 2013 at 7:32
  • Please post your code. The more information we have, the easier it is for us to find the problem. Commented May 29, 2013 at 7:35
  • where is line number 49 in Registration.java ? Commented May 29, 2013 at 7:44
  • 1
    if you got your answer then plz show some respect to ppl who helped you, at least single thanks??? Commented May 29, 2013 at 7:57

5 Answers 5

1

I believe the crash is here:

submit.setOnClickListener(new View.OnClickListener() {

You are missing a:

submit = (Button) findViewById(R.id.submit); // Or whatever your ID is

You also need to initialise cancel.

Sign up to request clarification or add additional context in comments.

Comments

0

you never initialize submit. In Jave you can not declare and use an Object without create it (you should call the new operator upon it). Probably you missed the findViewById of submit

Comments

0

Initialize your submit and cancel buttons. You are writing onClickListener for a non-initialized variable

submit = (Button) findViewById(R.id.id_of_your_submit_button);
cancel= (Button) findViewById(R.id.id_of_your_cancel_button);

Comments

0

Your submit button id not inintialized on the Registration Activity.but u used onclick listener on submit button.so initialized it first.hope ur problem may be solved.

Comments

0

Try this code:

submit = (Button) findViewById(R.id.yourID);
Submit.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        // your code here
    }
}

1 Comment

Welcome to Stack Overflow, when answering questions, please try to explain why you have posted the code in your response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.