android - getActionBar().setDisplayHomeAsUpEnabled(true); throws NullPointerException on new activity creation (Google - Basic Tutorial) -
i following this tutorial , getting nullpointerexception @ oncreate method of displaymessageactivity @ block of code:
if (build.version.sdk_int >= build.version_codes.honeycomb) { // show button in action bar. getactionbar().setdisplayhomeasupenabled(true); //exception here }
i running app @ emulator following nexusone avd template.
when click send button text typed in exception.
here log:
09-03 23:02:07.586: e/androidruntime(7095): fatal exception: main 09-03 23:02:07.586: e/androidruntime(7095): java.lang.runtimeexception: unable start activity componentinfo{com.mypackage.myfirstapp/com.mypackage.myfirstapp.displaymessageactivity}: java.lang.nullpointerexception 09-03 23:02:07.586: e/androidruntime(7095): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 09-03 23:02:07.586: e/androidruntime(7095): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 09-03 23:02:07.586: e/androidruntime(7095): @ android.app.activitythread.access$600(activitythread.java:141) 09-03 23:02:07.586: e/androidruntime(7095): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 09-03 23:02:07.586: e/androidruntime(7095): @ android.os.handler.dispatchmessage(handler.java:99) 09-03 23:02:07.586: e/androidruntime(7095): @ android.os.looper.loop(looper.java:137) 09-03 23:02:07.586: e/androidruntime(7095): @ android.app.activitythread.main(activitythread.java:5041) 09-03 23:02:07.586: e/androidruntime(7095): @ java.lang.reflect.method.invokenative(native method) 09-03 23:02:07.586: e/androidruntime(7095): @ java.lang.reflect.method.invoke(method.java:511) 09-03 23:02:07.586: e/androidruntime(7095): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 09-03 23:02:07.586: e/androidruntime(7095): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 09-03 23:02:07.586: e/androidruntime(7095): @ dalvik.system.nativestart.main(native method) 09-03 23:02:07.586: e/androidruntime(7095): caused by: java.lang.nullpointerexception 09-03 23:02:07.586: e/androidruntime(7095): @ com.mypackage.myfirstapp.displaymessageactivity.oncreate(displaymessageactivity.java:40) 09-03 23:02:07.586: e/androidruntime(7095): @ android.app.activity.performcreate(activity.java:5104) 09-03 23:02:07.586: e/androidruntime(7095): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 09-03 23:02:07.586: e/androidruntime(7095): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 09-03 23:02:07.586: e/androidruntime(7095): ... 11 more
by commenting block app runs successfuly.
why nullpointerexception thrown?
you using theme doesn't support actionbar
. hence getactionbar()
method throws nullpointerexception
.
trying using theme:
android:theme="@android:style/theme.holo.light"
Comments
Post a Comment