android - onSaveInstanceState() makes my app close -


i want use onsaveinstancestate() because have 5 pages , when ever result 1 page need go next one

but each time should save result in result activity when close go next page , come save new result previous result there

i used code (just page4 previous result , page5 new result) when run on device , click on page4 button send result result activity closes app

public class resault extends actionbaractivity { string ch44=""; static final string ch4 = ""; public final static string extra_massage = "massage"; public final static string extra_page = "page";       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_resault);          if (savedinstancestate != null) {             // restore value of members saved state             ch44 = savedinstancestate.getstring(ch4);             ((textview) findviewbyid(r.id.choice4)).settext(ch44);         } else {             string text = getintent().getstringextra(extra_massage);             if (text != null) {                 int page = getintent().getintextra(extra_page, -1);                 switch (page) {                     case 1:                         ((textview) findviewbyid(r.id.choice1)).settext(text);                         break;                     case 2:                         ((textview) findviewbyid(r.id.choice2)).settext(text);                         break;                     case 3:                         ((textview) findviewbyid(r.id.choice3)).settext(text);                         break;                     case 4:                         ((textview) findviewbyid(r.id.choice4)).settext(text);                         ch44 = text;                         onsaveinstancestate(savedinstancestate);                         startactivity(new intent(this, page5.class));                         break;                     case 5:                         ((textview) findviewbyid(r.id.choice5)).settext(text);                         break;                  }             }           }     }   @override public void onsaveinstancestate(bundle outstate) {     // save user's current game state     outstate.putstring(ch4,ch44);      // call superclass can save view hierarchy state     super.onsaveinstancestate(outstate); }    } 

i couldn't figure out problem

this logcat

08-03 13:25:28.487  27278-27278/ir.yazdanv.tabbatfaal w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x41684e00) 08-03 13:25:28.487  27278-27278/ir.yazdanv.tabbatfaal e/androidruntime﹕ fatal exception: main     process: ir.yazdanv.tabbatfaal, pid: 27278     java.lang.runtimeexception: unable start activity componentinfo{ir.yazdanv.tabbatfaal/ir.yazdanv.tabbatfaal.resault}: java.lang.nullpointerexception             @ android.app.activitythread.performlaunchactivity(activitythread.java:2264)             @ android.app.activitythread.handlelaunchactivity(activitythread.java:2313)             @ android.app.activitythread.access$1100(activitythread.java:141)             @ android.app.activitythread$h.handlemessage(activitythread.java:1238)             @ android.os.handler.dispatchmessage(handler.java:102)             @ android.os.looper.loop(looper.java:136)             @ android.app.activitythread.main(activitythread.java:5336)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:865)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:681)             @ dalvik.system.nativestart.main(native method)      caused by: java.lang.nullpointerexception             @ ir.yazdanv.tabbatfaal.resault.onsaveinstancestate(resault.java:64)             @ ir.yazdanv.tabbatfaal.resault.oncreate(resault.java:46)             @ android.app.activity.performcreate(activity.java:5302)             @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1090)             @ android.app.activitythread.performlaunchactivity(activitythread.java:2228)             at android.app.activitythread.handlelaunchactivity(activitythread.java:2313)             at android.app.activitythread.access$1100(activitythread.java:141)             at android.app.activitythread$h.handlemessage(activitythread.java:1238)             at android.os.handler.dispatchmessage(handler.java:102)             at android.os.looper.loop(looper.java:136)             at android.app.activitythread.main(activitythread.java:5336)             at java.lang.reflect.method.invokenative(native method)             at java.lang.reflect.method.invoke(method.java:515)             at    com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:865)             at com.android.internal.os.zygoteinit.main(zygoteinit.java:681)                        at dalvik.system.nativestart.main(native method) 

here reason:

case 4: ((textview) findviewbyid(r.id.choice4)).settext(text); ch44 = text;  onsaveinstancestate(savedinstancestate);// here  startactivity(new intent(this, page5.class)); break; 

this code in else case of savedinstancestate != null before.
when go here, savedinstancestate null -> force close.
please check again while need call onsaveinstance here?

and suggest should never call activty's lifecylce method yourself. it's framework's job. calling lifecycle method lead not correct thought when develop because it'll not work when called framework.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -