当我按下电源按钮锁定屏幕并再次按下它以解锁屏幕时,应用程序崩溃。屏幕解锁后应用程序崩溃。
这是我在 logcat 中得到的 stackTress:
05-09 18:46:57.254: E/AndroidRuntime(25354): FATAL EXCEPTION: main
05-09 18:46:57.254: E/AndroidRuntime(25354): java.lang.NullPointerException
05-09 18:46:57.254: E/AndroidRuntime(25354): at org.andengine.ui.activity.BaseGameActivity.onResumeGame(BaseGameActivity.java:222)
05-09 18:46:57.254: E/AndroidRuntime(25354): at org.andengine.ui.activity.BaseGameActivity$4.run(BaseGameActivity.java:373)
05-09 18:46:57.254: E/AndroidRuntime(25354): at android.os.Handler.handleCallback(Handler.java:615)
05-09 18:46:57.254: E/AndroidRuntime(25354): at android.os.Handler.dispatchMessage(Handler.java:92)
05-09 18:46:57.254: E/AndroidRuntime(25354): at android.os.Looper.loop(Looper.java:137)
05-09 18:46:57.254: E/AndroidRuntime(25354): at android.app.ActivityThread.main(ActivityThread.java:4744)
05-09 18:46:57.254: E/AndroidRuntime(25354): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 18:46:57.254: E/AndroidRuntime(25354): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 18:46:57.254: E/AndroidRuntime(25354): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-09 18:46:57.254: E/AndroidRuntime(25354): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-09 18:46:57.254: E/AndroidRuntime(25354): at dalvik.system.NativeStart.main(Native Method)
BaseGameActivityClass 的 onResumeGame() 方法出现 Nullpointer 异常。
我在清单的“活动”标签中添加了这一行
android:configChanges="orientation|keyboard|keyboardHidden"
在我扩展 BaseGameActivity 的 GameActivity 中,我添加了这个
@Override
public void onPause() {
super.onPause();
mEngine.stop();
}
@Override
protected void onResume() {
// The activity has become visible (it is now "resumed").
super.onResume();
mEngine.start();
}
怎么了?我应该怎么做才能停止在电源按钮问题上崩溃的游戏?