ActionBar实现滑动选项卡出现NullPointerException

异常内容:
<pre name="code" class="html">09-06 16:21:50.440  29864-29864/com.example.myapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x419bec80)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ java.lang.NullPointerException
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at com.example.myapp.MainActivity.setUpActionBar(MainActivity.java:53)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at com.example.myapp.MainActivity.onCreate(MainActivity.java:43)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5304)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2331)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.app.ActivityThread.access$1000(ActivityThread.java:143)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5291)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
09-06 16:22:51.630  30372-30372/com.example.myapp W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)


 

异常所在的53行代码为:52 final ActionBar actionBar = getActionBar();53    actionBar.setHomeButtonEnabled(false);

 
 

问题原因:AndroidManifest.xml中出现的问题,给MainActivity设定style后即正常


具体查看源码说明:

<!-- Honeycomb holographic theme (light version).  The widgets in the
         holographic theme are translucent on their brackground, so applications
         must ensure that any background they use with this theme is itself
         light; otherwise, it will be difficult to see the widgets.  This
         UI style also includes a full action bar by default. -->

大概意思:此主题中的部件在其所在背景中都是半透明(有光泽?英语不好,见谅~)的,因此应用程序必须确保此主题中组件所在背景都是自身背景色;否则很难看到那些部件(比如ActionBar)。这个UI样式默认包含action bar运行所需的所有样式。所有要使用ActionBar,需要给ActionBar所在的Activity设定主题样式


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值