LibGdx安卓游戏在恢复时因奇数键码而崩溃(1026)

时间:2015-01-11 18:29:56

标签: java android libgdx

在Android上运行时,我们的LibGdx项目在恢复时崩溃。

以下跟踪显示出现了什么问题。但无法弄清楚如何处理这个问题。

01-11 18:37:43.643  17046-17046/com.mojo.rainbowrun.android D/AndroidRuntime﹕ Shutting down VM
01-11 18:37:43.643  17046-17046/com.mojo.rainbowrun.android W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41675d88)
01-11 18:37:43.643  17046-17046/com.mojo.rainbowrun.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.mojo.rainbowrun.android, PID: 17046
    java.lang.ArrayIndexOutOfBoundsException: length=256; index=1026
            at com.badlogic.gdx.backends.android.AndroidInput.onKey(AndroidInput.java:561)
            at android.view.View.dispatchKeyEvent(View.java:7791)
            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
            at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2042)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1512)
            at android.app.Activity.dispatchKeyEvent(Activity.java:2418)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1969)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3852)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3558)
            at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3718)
            at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2087)
            at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1781)
            at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1772)
            at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2064)
            at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
            at android.os.MessageQueue.nativePollOnce(Native Method)
            at android.os.MessageQueue.next(MessageQueue.java:138)
            at android.os.Looper.loop(Looper.java:196)
            at android.app.ActivityThread.main(ActivityThread.java:5137)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718)
            at dalvik.system.NativeStart.main(Native Method)

以下是AndroidInput.java的第561行的代码段:

            if (keyCode == Keys.BUTTON_CIRCLE) {
                if (keys[Keys.BUTTON_CIRCLE]) {
                    keyCount--;
                    keys[Keys.BUTTON_CIRCLE] = false;
                }
            } else {
                if (keys[e.getKeyCode()]) { // Line 561
                    keyCount--;
                    keys[e.getKeyCode()] = false;
            }

keys数组有256个条目,因此Libgdx不会期望一个大到1026的密钥代码。

1 个答案:

答案 0 :(得分:0)

在第561行中,if语句有一个数组,当if语句编码执行时,你得到的是keycode作为索引变量,这可能导致数组越界,就像Logcat所说的那样。如果这导致问题,请尝试更改它,看看它是否解决了问题。

第561行中的 if语句使用 else 语句执行。如果第一个 if false 。验证您是否可以更改该行中的代码并查看这是否真的导致崩溃,我不知道 e 对象的含义是什么,因为您没有在代码中发布他的工作内容