0

我的代码的错误部分:

        System.out.println(frame + ", " + ((frame / 10) % 2) + ", " + dyingBoxRelated[1] + ", "
                + (bad[dyingBoxRelated[1]][0] - radBad) + ", "
                + (bad[dyingBoxRelated[1]][1] - radBad) + ", " + radBad + ", "
                + littleBad[(frame / 10) % 2]);
        try {
            canvas.drawBitmap(littleBad[(frame / 10) % 2], bad[dyingBoxRelated[1]][0] - radBad,
                    bad[dyingBoxRelated[1]][1] - radBad, null);
        } catch (Exception e) {
            System.out.println(e);
        }

我真的不明白这里发生了什么。我在 try-catch 上方添加了一个 System.out 来观察变量的所有值,这就是我得到的:

...
06-04 10:35:48.785: I/System.out(9786): 409, 0, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fbd428
06-04 10:35:48.830: I/System.out(9786): 410, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:48.875: I/System.out(9786): 411, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:48.915: I/System.out(9786): 412, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:48.955: I/System.out(9786): 413, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:48.995: I/System.out(9786): 414, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:49.045: I/System.out(9786): 415, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:49.095: I/System.out(9786): 416, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:49.140: I/System.out(9786): 417, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:49.145: I/System.out(9786): java.lang.ArrayIndexOutOfBoundsException: length=2; index=-1646894335
06-04 10:35:49.185: I/System.out(9786): 418, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:49.185: I/System.out(9786): java.lang.ArrayIndexOutOfBoundsException: length=2; index=-45811
06-04 10:35:49.230: I/System.out(9786): 419, 1, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fc0a18
06-04 10:35:49.230: I/System.out(9786): java.lang.ArrayIndexOutOfBoundsException: length=2; index=-45811
06-04 10:35:49.270: I/System.out(9786): 420, 0, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fbd428
06-04 10:35:49.270: I/System.out(9786): java.lang.ArrayIndexOutOfBoundsException: length=2; index=-45812
06-04 10:35:49.315: I/System.out(9786): 421, 0, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fbd428
06-04 10:35:49.315: I/System.out(9786): java.lang.ArrayIndexOutOfBoundsException: length=2; index=-45812
06-04 10:35:49.355: I/System.out(9786): 422, 0, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fbd428
06-04 10:35:49.355: I/System.out(9786): java.lang.ArrayIndexOutOfBoundsException: length=2; index=-45812
06-04 10:35:49.395: I/System.out(9786): 423, 0, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fbd428
06-04 10:35:49.395: I/System.out(9786): java.lang.ArrayIndexOutOfBoundsException: length=2; index=-45812
06-04 10:35:49.435: I/System.out(9786): 424, 0, 1, 484.2473, 34.78183, 50.0, android.graphics.Bitmap@40fbd428
06-04 10:35:49.435: I/System.out(9786): java.lang.ArrayIndexOutOfBoundsException: length=2; index=-45812
...

一切都很顺利,直到某个时候我开始出现 ArrayIndexOutOfBoundsException 错误......这是怎么回事?为什么应用程序在尝试显示值时不会在 System.out 崩溃?lenght=2 的唯一变量是 littleBad[]... 它是 drawBitmap 方法内部的东西吗?

4

0 回答 0