0

The faulty part of my code:

        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);
        }

I can't really understand what's going on here. I have added a System.out above the try-catch to watch all the values of the variables and this is what I get:

...
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
...

Everything goes well until at some point I'm starting to get ArrayIndexOutOfBoundsException errors... What's going on? Why doesn't the app crash at System.out when it's trying to display the values? The only variable there with lenght=2 is the littleBad[]... Is it something internal of the drawBitmap method?

rtsketo
  • 1,168
  • 11
  • 18
  • 1
    most of all it is invalid index you are using for your arrays `littleBad` or `bad` or `dyingBoxRelated`. Extract that assignment to separate variables and you will know more. Also instead of doing `System.out.println(e);` do `Log.e(TAG, e)` – Eugene Popovich Jun 04 '13 at 08:08
  • no, put accessing an array can. – njzk2 Jun 04 '13 at 08:08
  • There's nothing invalid... I'm displaying all the values of the variables... – rtsketo Jun 04 '13 at 10:23

0 Answers0