Android getting Int from another activity -


what trying achieve when click on image button adds 1 int, when go stats page display int in textview, when click on stats button application crashes.


color class

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_color);      blue = (imagebutton)findviewbyid(r.id.imagebutton1);       blue.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {              tb1.settext("blue");             bl1++;           }     });      home.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {              intent intent  = new intent(v.getcontext(), mainactivity.class);              intent.putextra("blue1", bl1);              startactivityforresult(intent, 0);           }     }); 

stats class

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_stats);      theblue = (textview)findviewbyid(r.id.textview1);     theblue.settext(getintent().getextras().getint("blue1"));   }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.stats, menu);     return true; }  } 

04-18 05:30:12.645: w/dalvikvm(790): threadid=1: thread exiting uncaught exception (group=0x40a71930) 04-18 05:30:12.685: e/androidruntime(790): fatal exception: main 04-18 05:30:12.685: e/androidruntime(790): java.lang.runtimeexception: unable start activity componentinfo{com.example.childapp/com.example.childapp.stats}: java.lang.nullpointerexception 04-18 05:30:12.685: e/androidruntime(790):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 04-18 05:30:12.685: e/androidruntime(790):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 04-18 05:30:12.685: e/androidruntime(790):  @ android.app.activitythread.access$600(activitythread.java:141) 04-18 05:30:12.685: e/androidruntime(790):  @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 04-18 05:30:12.685: e/androidruntime(790):  @ android.os.handler.dispatchmessage(handler.java:99) 04-18 05:30:12.685: e/androidruntime(790):  @ android.os.looper.loop(looper.java:137) 04-18 05:30:12.685: e/androidruntime(790):  @ android.app.activitythread.main(activitythread.java:5041) 04-18 05:30:12.685: e/androidruntime(790):  @ java.lang.reflect.method.invokenative(native method) 04-18 05:30:12.685: e/androidruntime(790):  @ java.lang.reflect.method.invoke(method.java:511) 04-18 05:30:12.685: e/androidruntime(790):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 04-18 05:30:12.685: e/androidruntime(790):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 04-18 05:30:12.685: e/androidruntime(790):  @ dalvik.system.nativestart.main(native method) 04-18 05:30:12.685: e/androidruntime(790): caused by: java.lang.nullpointerexception 04-18 05:30:12.685: e/androidruntime(790):  @ com.example.childapp.stats.oncreate(stats.java:19) 04-18 05:30:12.685: e/androidruntime(790):  @ android.app.activity.performcreate(activity.java:5104) 04-18 05:30:12.685: e/androidruntime(790):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 04-18 05:30:12.685: e/androidruntime(790):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 04-18 05:30:12.685: e/androidruntime(790):  ... 11 more 

  1. first put log check whether value passing in intent or not.
    if succeeds:
  2. then use code value.

    theblue.settext(""+getintent().getextras().getint("blue1")); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -