java - android app parse values through intent -


i trying parse value through intent while switching between activities. know should read values last intent getextra don't know why doesn't work.

also when switch between activities on button click, application crashes.

in activity main read text edittext , put in intent:

public void schimba(view view){     int value = integer.parseint(instances.gettext().tostring());;     intent intent = new intent(this, tabel.class);     intent.putextra("max", value);     startactivity(intent); } 

when switch activity 2 have this:

intent intentobject = getintent(); int value;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     value = intentobject.getintextra("max", 0);     /*     for(i=0;i<=value;i++)     {         layoutinflater layoutinflate = null;          layoutinflate = (layoutinflater) getsystemservice(context.layout_inflater_service);          final view rowview = layoutinflate.inflate( r.layout.activity_tabel, null);     }     */     setcontentview(r.layout.activity_tabel);      textview showvalue;     showvalue = (textview) findviewbyid(r.id.showvalue);     showvalue.settext(""+value); 

the idea want use value in loop, know how display value in textview don't need it, wanna use in for.

logcat:

04-23 10:40:52.550: e/androidruntime(1010): fatal exception: main 04-23 10:40:52.550: e/androidruntime(1010): java.lang.runtimeexception: unable start activity componentinfo{com.example.instances_temperature/com.example.instances_temperature.tabel}: java.lang.nullpointerexception 04-23 10:40:52.550: e/androidruntime(1010):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2663) 04-23 10:40:52.550: e/androidruntime(1010):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2679) 04-23 10:40:52.550: e/androidruntime(1010):     @ android.app.activitythread.access$2300(activitythread.java:125) 04-23 10:40:52.550: e/androidruntime(1010):     @ android.app.activitythread$h.handlemessage(activitythread.java:2033) 04-23 10:40:52.550: e/androidruntime(1010):     @ android.os.handler.dispatchmessage(handler.java:99) 04-23 10:40:52.550: e/androidruntime(1010):     @ android.os.looper.loop(looper.java:123) 04-23 10:40:52.550: e/androidruntime(1010):     @ android.app.activitythread.main(activitythread.java:4627) 04-23 10:40:52.550: e/androidruntime(1010):     @ java.lang.reflect.method.invokenative(native method) 04-23 10:40:52.550: e/androidruntime(1010):     @ java.lang.reflect.method.invoke(method.java:521) 04-23 10:40:52.550: e/androidruntime(1010):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 04-23 10:40:52.550: e/androidruntime(1010):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 04-23 10:40:52.550: e/androidruntime(1010):     @ dalvik.system.nativestart.main(native method) 04-23 10:40:52.550: e/androidruntime(1010): caused by: java.lang.nullpointerexception 04-23 10:40:52.550: e/androidruntime(1010):     @ com.example.instances_temperature.tabel.oncreate(tabel.java:26) 04-23 10:40:52.550: e/androidruntime(1010):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 04-23 10:40:52.550: e/androidruntime(1010):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2627) 04-23 10:40:52.550: e/androidruntime(1010):     ... 11 more 

line 26 this:

value = intentobject.getintextra("max", 0); 

you have use code below

int maxvalue = getintent().getextras().getint("max"); 

inside oncreate().

hope solve problem..


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -