How can repair this error? “java.lang.IndexOutOfBoundsException”

回眸只為那壹抹淺笑 提交于 2019-12-01 14:05:17

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

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.

detach entity in onManagedUpdate of scene.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!