java.lang.IndexOutOfBoundsException: Invalid index 13, size is 13

左心房为你撑大大i 提交于 2019-12-01 19:40:26
Robadob

In programming indexes often start at 0, so if you have 9 items, the highest index would be 8.

The actual error is being thrown from some code within the library you are using

org.anddev.andengine.entity.Entity.onManagedDrawChildren(Entity.java:1008)

It is likely that you are changing the list in a separate thread whilst the library is also interacting with the list.


From the gcode project;

    public void onManagedDrawChildren(final Camera pCamera) {
            final ArrayList<IEntity> children = this.mChildren;
            final int childCount = children.size();
            for(int i = 0; i < childCount; i++) {
                    children.get(i).onDraw(pCamera);
            }
    }

As this is running in a separate thread, it is likely that you are removing an object from the children ArrayList while the loop is iterating. To fix this you should call your changes to the children ArrayList like jmr499485 explains in his answer.

java.lang.IndexOutOfBoundsException: Invalid index 13, size is 13

The only item in your code I can see that would be causing this is the statement questionText.detachSelf(); which you have used in many places. You should instead use;

runOnUpdateThread(new Runnable() {
@Override
public void run() {
    questionText.detachSelf();
}
});
jmroyalty

This typically happens when you remove something from the screen and don't do it on the updateThread. Make sure that any place you are removing items that you call it like this

runOnUpdateThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
   //remove/detach your stuff in here
}
});

See this similar question - How can repair this error? "java.lang.IndexOutOfBoundsException"

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