我提前道歉,因为我对Android开发缺乏了解,我对此非常陌生。
我在java中创建了一个从头开始编写的游戏。如果我按下菜单按钮或后退按钮,游戏将立即崩溃。我相信它会在菜单按钮上崩溃,因为我正在使用Window。 FEATURE_NO_TITLE ,我不知道为什么后退按钮会崩溃游戏(有时它会让游戏崩溃,有时它会退出游戏,然后,当我再次打开它时,游戏将崩溃。 如果我按下主页按钮,然后尝试返回应用程序,它也会崩溃,我猜这与 surfaceCreated 方法有关。
基本上,我不需要这些按钮来做任何事情,所以我真正想做的就是禁用它们,听起来很简单,但我没有成功。
编辑:logcat:
04-14 21:31:25.682: E/InputEventSender(24686): Exception dispatching finished signal.
04-14 21:31:25.682: E/MessageQueue-JNI(24686): Exception in MessageQueue callback: handleReceiveCallback
04-14 21:31:25.712: E/MessageQueue-JNI(24686): java.lang.NullPointerException
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarImplICS.getThemedContext(ActionBarImplICS.java:302)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarImplJB.getThemedContext(ActionBarImplJB.java:20)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarActivityDelegate.getActionBarThemedContext(ActionBarActivityDelegate.java:208)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarActivityDelegate.getMenuInflater(ActionBarActivityDelegate.java:98)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarActivity.getMenuInflater(ActionBarActivity.java:71)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.app.Activity.onCreatePanelMenu(Activity.java:2579)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:224)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:199)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:507)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at com.android.internal.policy.impl.PhoneWindow.onKeyDownPanel(PhoneWindow.java:964)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at com.android.internal.policy.impl.PhoneWindow.onKeyDown(PhoneWindow.java:1670)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2227)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4547)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4523)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4128)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4178)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4147)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4232)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4155)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4289)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4128)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4178)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4147)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4155)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4128)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4178)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4147)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4265)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4415)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2213)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1885)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1876)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2190)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.os.MessageQueue.nativePollOnce(Native Method)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.os.MessageQueue.next(MessageQueue.java:132)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.os.Looper.loop(Looper.java:124)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at android.app.ActivityThread.main(ActivityThread.java:5450)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at java.lang.reflect.Method.invokeNative(Native Method)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at java.lang.reflect.Method.invoke(Method.java:525)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-14 21:31:25.712: E/MessageQueue-JNI(24686): at dalvik.system.NativeStart.main(Native Method)
04-14 21:31:25.712: D/AndroidRuntime(24686): Shutting down VM
04-14 21:31:25.712: W/dalvikvm(24686): threadid=1: thread exiting with uncaught exception (group=0x41d3f898)
04-14 21:31:25.732: E/AndroidRuntime(24686): FATAL EXCEPTION: main
04-14 21:31:25.732: E/AndroidRuntime(24686): java.lang.NullPointerException
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarImplICS.getThemedContext(ActionBarImplICS.java:302)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarImplJB.getThemedContext(ActionBarImplJB.java:20)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarActivityDelegate.getActionBarThemedContext(ActionBarActivityDelegate.java:208)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarActivityDelegate.getMenuInflater(ActionBarActivityDelegate.java:98)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarActivity.getMenuInflater(ActionBarActivity.java:71)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.app.Activity.onCreatePanelMenu(Activity.java:2579)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:224)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:199)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
04-14 21:31:25.732: E/AndroidRuntime(24686): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:507)
04-14 21:31:25.732: E/AndroidRuntime(24686): at com.android.internal.policy.impl.PhoneWindow.onKeyDownPanel(PhoneWindow.java:964)
04-14 21:31:25.732: E/AndroidRuntime(24686): at com.android.internal.policy.impl.PhoneWindow.onKeyDown(PhoneWindow.java:1670)
04-14 21:31:25.732: E/AndroidRuntime(24686): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2227)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4547)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4523)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4128)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4178)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4147)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4232)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4155)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4289)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4128)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4178)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4147)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4155)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4128)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4178)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4147)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4265)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4415)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2213)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1885)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1876)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2190)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.os.MessageQueue.nativePollOnce(Native Method)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.os.MessageQueue.next(MessageQueue.java:132)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.os.Looper.loop(Looper.java:124)
04-14 21:31:25.732: E/AndroidRuntime(24686): at android.app.ActivityThread.main(ActivityThread.java:5450)
04-14 21:31:25.732: E/AndroidRuntime(24686): at java.lang.reflect.Method.invokeNative(Native Method)
04-14 21:31:25.732: E/AndroidRuntime(24686): at java.lang.reflect.Method.invoke(Method.java:525)
04-14 21:31:25.732: E/AndroidRuntime(24686): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-14 21:31:25.732: E/AndroidRuntime(24686): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-14 21:31:25.732: E/AndroidRuntime(24686): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
为自己找出一个解决方案,因为我正在使用Window。 FEATURE_NO_TITLE 我意识到当我按下菜单按钮时,ActionBarActivity的扩展会让它崩溃,所以我把它改成只是扩展了Acitivity。为了解决关闭并重新加载,我刚用 surfaceDestroyed 方法杀死了游戏。
我不知道为什么选择ActionBarActivity作为默认值。