我已经更新了API 21,工具和附加功能,一些项目中的Actionbar变得不可见.我在下面的代码中做了这个,但app崩溃显示NullPointerException.
Actionbar actionbar = getActionbar();actionbar.show();
Logcat输出
02-23 18:03:36.269: E/AndroIDRuntime(3327): FATAL EXCEPTION: main
02-23 18:03:36.269: E/AndroIDRuntime(3327): Process: com.example.twaapp, PID: 3327
02-23 18:03:36.269: E/AndroIDRuntime(3327): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.twaapp/com.example.twaapp.MainActivity}: java.lang.NullPointerException
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2198)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.app.ActivityThread.access$800(ActivityThread.java:139)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.os.Handler.dispatchMessage(Handler.java:102)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.os.Looper.loop(Looper.java:136)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.app.ActivityThread.main(ActivityThread.java:5086)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at java.lang.reflect.Method.invoke(Method.java:515)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:601)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at dalvik.system.NativeStart.main(Native Method)
02-23 18:03:36.269: E/AndroIDRuntime(3327): Caused by: java.lang.NullPointerException
02-23 18:03:36.269: E/AndroIDRuntime(3327): at com.example.twaapp.MainActivity.onCreate(MainActivity.java:82)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.app.Activity.performCreate(Activity.java:5248)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
02-23 18:03:36.269: E/AndroIDRuntime(3327): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2162)
02-23 18:03:36.269: E/AndroIDRuntime(3327): … 11 more
如何让AB可见?
解决方法:
确保您的活动扩展了ActionBaractivity.像这样:MainActivity扩展了ActionBaractivity.我发现当我删除它并扩展其他 *** 作栏会消失的东西时.还要检查xml的主题并进行更改.
看一下这个:
can I use a compatible action bar AND a fragment in the same activity?
总结以上是内存溢出为你收集整理的java – Android ActionBar不可见全部内容,希望文章能够帮你解决java – Android ActionBar不可见所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)