<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设定主题样式