java - Passing an int variable to another activity makes the app crash,using putExtras -
i trying pass specific int variable through class crashes program. please have look:
first activity
public void highquiz(view view){ intent j= new intent(this,highscoretable.class); j.putextra("new_variable_name",(int)lowerint); startactivityforresult(j, 0); }
second activity
textview hs1 = (textview)findviewbyid(r.id.textview1); bundle extras = getintent().getextras(); if (extras != null) { int lowerint= extras.getint("new_variable_name"); hs1.settext(""+lowerint); }
log
04-29 18:36:21.243: e/androidruntime(2104): fatal exception: main 04-29 18:36:21.243: e/androidruntime(2104): process: oxley.it, pid: 2104 04-29 18:36:21.243: e/androidruntime(2104): java.lang.runtimeexception: unable start activity componentinfo{oxley.it/oxley.it.highscoretable}: java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.textview.settext(java.lang.charsequence)' on null object reference 04-29 18:36:21.243: e/androidruntime(2104): @ android.app.activitythread.performlaunchactivity(activitythread.java:2298) 04-29 18:36:21.243: e/androidruntime(2104): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2360) 04-29 18:36:21.243: e/androidruntime(2104): @ android.app.activitythread.access$800(activitythread.java:144) 04-29 18:36:21.243: e/androidruntime(2104): @ android.app.activitythread$h.handlemessage(activitythread.java:1278) 04-29 18:36:21.243: e/androidruntime(2104): @ android.os.handler.dispatchmessage(handler.java:102) 04-29 18:36:21.243: e/androidruntime(2104): @ android.os.looper.loop(looper.java:135) 04-29 18:36:21.243: e/androidruntime(2104): @ android.app.activitythread.main(activitythread.java:5221) 04-29 18:36:21.243: e/androidruntime(2104): @ java.lang.reflect.method.invoke(native method) 04-29 18:36:21.243: e/androidruntime(2104): @ java.lang.reflect.method.invoke(method.java:372) 04-29 18:36:21.243: e/androidruntime(2104): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) 04-29 18:36:21.243: e/androidruntime(2104): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694) 04-29 18:36:21.243: e/androidruntime(2104): caused by: java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.textview.settext(java.lang.charsequence)' on null object reference 04-29 18:36:21.243: e/androidruntime(2104): @ oxley.it.highscoretable.oncreate(highscoretable.java:25) 04-29 18:36:21.243: e/androidruntime(2104): @ android.app.activity.performcreate(activity.java:5933) 04-29 18:36:21.243: e/androidruntime(2104): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1105) 04-29 18:36:21.243: e/androidruntime(2104): @ android.app.activitythread.performlaunchactivity(activitythread.java:2251) 04-29 18:36:21.243: e/androidruntime(2104): ... 10 more
try
if(getintent().hasextra("new_variable_name")) getintent().getintextra("new_variable_name");
Comments
Post a Comment