应用主题时出现空指针错误

时间:2014-01-13 20:45:58

标签: android

我在我的清单中设置了主题android Holo.Light.NoActionBar,但我有这个错误:

    01-13 21:52:21.968: E/AndroidRuntime(25087): FATAL EXCEPTION: main
01-13 21:52:21.968: E/AndroidRuntime(25087): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.com/com.com.Home}: java.lang.NullPointerException
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.os.Looper.loop(Looper.java:137)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.app.ActivityThread.main(ActivityThread.java:4898)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at java.lang.reflect.Method.invokeNative(Native Method)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at java.lang.reflect.Method.invoke(Method.java:511)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at dalvik.system.NativeStart.main(Native Method)
01-13 21:52:21.968: E/AndroidRuntime(25087): Caused by: java.lang.NullPointerException
01-13 21:52:21.968: E/AndroidRuntime(25087):    at felastech.websourcerequest.Home.onCreate(Home.java:51)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.app.Activity.performCreate(Activity.java:5206)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
01-13 21:52:21.968: E/AndroidRuntime(25087):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
01-13 21:52:21.968: E/AndroidRuntime(25087):    ... 11 moreactivity ComponentInfo{com.com/com.com.Home}: java.lang.NullPointerException

代码:

<activity
       android:name="com.com"
       android:label="@string/app_name" 
      android:theme="@android:style/Theme.Holo.Light.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

如果我删除:

android:theme="@android:style/Theme.Holo.Light.NoActionBar"

一切正常......

1 个答案:

答案 0 :(得分:0)

我在我的Home.java中解析了我删除它:

ActionBar ab = getActionBar();
ab.setHomeButtonEnabled(true);