Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android drawBitmap能否将ArrayIndex抛出BoundsException?_Android_Indexoutofboundsexception_Drawbitmap - Fatal编程技术网

Android drawBitmap能否将ArrayIndex抛出BoundsException?

Android drawBitmap能否将ArrayIndex抛出BoundsException?,android,indexoutofboundsexception,drawbitmap,Android,Indexoutofboundsexception,Drawbitmap,我的代码的错误部分: System.out.println(frame + ", " + ((frame / 10) % 2) + ", " + dyingBoxRelated[1] + ", " + (bad[dyingBoxRelated[1]][0] - radBad) + ", " + (bad[dyingBoxRelated[1]][1] - radBad) + ", " + radBad + ", "

我的代码的错误部分:

        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崩溃? 那里唯一长度为2的变量是littleBad[]。。。
它是drawBitmap方法的内部内容吗?

最重要的是,它是用于数组的无效索引
littleBad
bad
dyingBoxRelated
。将赋值提取到单独的变量中,您将了解更多。也不是做
System.out.println(e)
do
Log.e(TAG,e)
no,put访问数组可以。没有无效的。。。我正在显示变量的所有值。。。