Android: Error when pressing back button, even after finishing the previous activity -


i getting nullpointer exception somewhere near line using getintent.getextra().

this error log:

 04-25 14:19:43.718: e/androidruntime(10031): fatal exception: main  04-25 14:19:43.718: e/androidruntime(10031): java.lang.runtimeexception: unable start     activity componentinfo{com.example.attendence/com.example.attendence.userpage}:  java.lang.nullpointerexception  04-25 14:19:43.718: e/androidruntime(10031):   @ android.app.activitythread.performlaunchactivity(activitythread.java:1651)  04-25 14:19:43.718: e/androidruntime(10031):   @ android.app.activitythread.handlelaunchactivity(activitythread.java:1667)  04-25 14:19:43.718: e/androidruntime(10031):   @ android.app.activitythread.access$1500(activitythread.java:117)  04-25 14:19:43.718: e/androidruntime(10031):   @ android.app.activitythread$h.handlemessage(activitythread.java:935)  04-25 14:19:43.718: e/androidruntime(10031):   @ android.os.handler.dispatchmessage(handler.java:99)  04-25 14:19:43.718: e/androidruntime(10031):   @ android.os.looper.loop(looper.java:130)  04-25 14:19:43.718: e/androidruntime(10031):   @ android.app.activitythread.main(activitythread.java:3687)  04-25 14:19:43.718: e/androidruntime(10031):   @ java.lang.reflect.method.invokenative(native method)  04-25 14:19:43.718: e/androidruntime(10031):   @ java.lang.reflect.method.invoke(method.java:507)  04-25 14:19:43.718: e/androidruntime(10031):   @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:867)  04-25 14:19:43.718: e/androidruntime(10031):   @ com.android.internal.os.zygoteinit.main(zygoteinit.java:625)  04-25 14:19:43.718: e/androidruntime(10031):   @ dalvik.system.nativestart.main(native method)  04-25 14:19:43.718: e/androidruntime(10031): caused by: java.lang.nullpointerexception  04-25 14:19:43.718: e/androidruntime(10031):   @ com.example.attendence.userpage.oncreate(userpage.java:52)  04-25 14:19:43.718: e/androidruntime(10031):   @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047)  04-25 14:19:43.718: e/androidruntime(10031):   @ android.app.activitythread.performlaunchactivity(activitythread.java:1615)  04-25 14:19:43.718: e/androidruntime(10031):   ... 11 more 

this code iam using call second activity(which called userpage) in first activity:

            startactivity(new intent(hellouser.this, userpage.class));             intent= new intent(hellouser.this, userpage.class);             intent.putextra("title11", "p");             intent.putextra("name", et.gettext().tostring().trim());             startactivity(intent);              finish(); 

as can see calling finish() button should not work in next activity.

this second activity called userpage, in error coming:

  public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     requestwindowfeature(window.feature_custom_title);     setcontentview(r.layout.userpage);      getwindow().setfeatureint(window.feature_custom_title, r.layout.window_title);      title11= (string)getintent().getstringextra("title11");     name= (string)getintent().getstringextra("name");     if(title11.equals("new"))     {         title11=null;         userpage.this.runonuithread(new runnable() {             public void run() {                 alertdialog.builder builder = new alertdialog.builder(userpage.this);                 builder.settitle("welcome");                 builder.setmessage("hello "+name)                          .setcancelable(false)                        .setpositivebutton("ok", new dialoginterface.onclicklistener() {                            public void onclick(dialoginterface dialog, int id) {                            }                        });                                      alertdialog alert = builder.create();                 alert.show();                            }         });     }     t1=(textview)findviewbyid(r.id.titlename);     t2=(textview)findviewbyid(r.id.gname);     t1.settext(name);     t2.getbackground().setalpha(55);      t2.setonclicklistener(new onclicklistener() {        @override        public void onclick(view v) {             startactivity(new intent(userpage.this, creategroup.class));        }     });  } } 

error coming on line " if(title11.equals("new"))" when press button.

startactivity(new intent(hellouser.this, userpage.class));             intent= new intent(hellouser.this, userpage.class);             intent.putextra("title11", "p");             intent.putextra("name", et.gettext().tostring().trim());             startactivity(intent);              finish(); 

you're starting activity 2 times, first 1 started can't find title11. try instead :

 intent= new intent(hellouser.this, userpage.class);                 intent.putextra("title11", "p");                 intent.putextra("name", et.gettext().tostring().trim());                 startactivity(intent);                  finish(); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -