• Android Sudoku应用挂掉的问题


    在真机上测试数独游戏时发现,快速点击屏幕时,游戏偶尔出现挂死的情况,Log如下

    04-08 15:35:00.838    7317-7356/org.elvalad.sudoku D/OpenGLRenderer﹕ Enabling debug mode 0
    04-08 15:35:23.036    7317-7317/org.elvalad.sudoku E/InputEventReceiver﹕ Exception dispatching input event.
    04-08 15:35:23.036    7317-7317/org.elvalad.sudoku E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
    04-08 15:35:23.041    7317-7317/org.elvalad.sudoku E/MessageQueue-JNI﹕ java.lang.ArrayIndexOutOfBoundsException: length=81; index=83
                at org.elvalad.sudoku.GameView.onTouchEvent(GameView.java:282)
                at android.view.View.dispatchTouchEvent(View.java:8393)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
                at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2314)
                at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1692)
                at android.app.Activity.dispatchTouchEvent(Activity.java:2749)
                at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2275)
                at android.view.View.dispatchPointerEvent(View.java:8583)
                at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4091)
                at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3957)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3562)
                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3528)
                at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3638)
                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3536)
                at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3695)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3562)
                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3528)
                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3536)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
                at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5806)
                at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5745)
                at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5716)
                at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5896)
                at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:192)
                at android.os.MessageQueue.nativePollOnce(Native Method)
                at android.os.MessageQueue.next(MessageQueue.java:143)
                at android.os.Looper.loop(Looper.java:122)
                at android.app.ActivityThread.main(ActivityThread.java:5312)
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:372)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
    04-08 15:35:23.041    7317-7317/org.elvalad.sudoku D/AndroidRuntime﹕ Shutting down VM
    04-08 15:35:23.042    7317-7317/org.elvalad.sudoku E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: org.elvalad.sudoku, PID: 7317
        java.lang.ArrayIndexOutOfBoundsException: length=81; index=83
                at org.elvalad.sudoku.GameView.onTouchEvent(GameView.java:282)
                at android.view.View.dispatchTouchEvent(View.java:8393)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2432)
                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
                at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2314)
                at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1692)
                at android.app.Activity.dispatchTouchEvent(Activity.java:2749)
                at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2275)
                at android.view.View.dispatchPointerEvent(View.java:8583)
                at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4091)
                at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3957)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3562)
                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3528)
                at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3638)
                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3536)
                at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3695)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3562)
                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3528)
                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3536)
                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3509)
                at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5806)
                at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5745)
                at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5716)
                at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5896)
                at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:192)
                at android.os.MessageQueue.nativePollOnce(Native Method)
                at android.os.MessageQueue.next(MessageQueue.java:143)
                at android.os.Looper.loop(Looper.java:122)
                at android.app.ActivityThread.main(ActivityThread.java:5312)
                at java.lang.reflect.Method.invoke(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:372)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

    从Log中可以很容易的发现是数组越界了,说明我们在游戏中绘制游戏格子时坐标并不是完全正确的,一个简单的处理办法是我们在使用数组时添加保护机制,当数组的Index大于81时直接让这次touch屏幕动作无效即可。

  • 相关阅读:
    POJ-1502-MPI Maelstrom
    POJ-3259-Wormholes
    【BZOJ4399】—膜法少女LJJ(线段树合并)
    省选模板复习—【计算几何】
    【BZOJ2115】【WC2011】—Xor(线性基)
    【洛谷P5290】【十二省联考2019】春节十二响(贪心+启发式合并)
    【BZOJ5461】 【PKUWC2018】—Minimax(线段树合并优化dp)
    【LOJ#3043】【洛谷P5280】【ZJOI2019】—线段树(计数dp+线段树)
    【省选模拟】—猎人杀(概率dp)
    【BZOJ4828】【HNOI2017】—大佬(LmyAKIOI!)
  • 原文地址:https://www.cnblogs.com/elvalad/p/4405320.html
Copyright © 2020-2023  润新知