Skip to content Skip to sidebar Skip to footer

How Can Repair This Error? "java.lang.indexoutofboundsexception"

I'm trying to do a game with andengine library. When the Sprite Enemy1Sprite reach the top of the camera, and I detach it, this exception is thrown : java.lang.IndexOutOfBoundsEx

Solution 1:

You've answered your own question really - Marcelo is correct, the issue is not in the code you posted, it's where you are doing the detachChild call - you need to call that on the Update Thread, as in

runOnUpdateThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
    yourScene.detachChild(yourEnemySprite);
}
});

Solution 2:

This says that your actual array size is 12 so your last index is 11. But you are trying to access index 12 which does not exist. Try to find out the line which throws this error. Make a condition there that if size of index is >= size of array brake.

Also you may try using try{}catch(IndexOutOfBondException e){} and continue the process.

Solution 3:

detach entity in onManagedUpdate of scene.

Post a Comment for "How Can Repair This Error? "java.lang.indexoutofboundsexception""