我希望堆栈跟踪能讲述这个故事。作为典型,我setupActionBar()
在里面调用onCreate
并且代码setupActionBar()
是自动生成的
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
也许其他人经历过类似的事情。我的清单、布局、字符串资源或我能看到的任何地方都没有红线。
04-06 09:59:25.913: E/AndroidRuntime(628): FATAL EXCEPTION: main
04-06 09:59:25.913: E/AndroidRuntime(628): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.game.example/com.game.example.WeaponActivity}: java.lang.NullPointerException
04-06 09:59:25.913: E/AndroidRuntime(628): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.os.Handler.dispatchMessage(Handler.java:99)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.os.Looper.loop(Looper.java:137)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-06 09:59:25.913: E/AndroidRuntime(628): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 09:59:25.913: E/AndroidRuntime(628): at java.lang.reflect.Method.invoke(Method.java:511)
04-06 09:59:25.913: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-06 09:59:25.913: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-06 09:59:25.913: E/AndroidRuntime(628): at dalvik.system.NativeStart.main(Native Method)
04-06 09:59:25.913: E/AndroidRuntime(628): Caused by: java.lang.NullPointerException
04-06 09:59:25.913: E/AndroidRuntime(628): at com.game.example.WeaponActivity.setupActionBar(WeaponActivity.java:103)
04-06 09:59:25.913: E/AndroidRuntime(628): at com.game.example.WeaponActivity.onCreate(WeaponActivity.java:38)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.app.Activity.performCreate(Activity.java:5008)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-06 09:59:25.913: E/AndroidRuntime(628): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-06 09:59:25.913: E/AndroidRuntime(628): ... 11 more