使用 sprite 表时,我在 andengine 中不断收到此错误。
谁能解释一下我的意思吗?
08-30 13:31:50.053: E/AndroidRuntime(9643): java.lang.ArrayIndexOutOfBoundsException: length=12; index=12
这里是发生错误的地方。
pItem.setCurrentTileIndex(MathUtils.random(0, pItem.getTileCount()));
最佳答案
我的猜测是,MathUtils.random
是包容性的,这意味着在您的示例中(大小为 12 的数组),它将生成一个从 0 到 12 的数字,包括 12. 尝试将代码更改为:
pItem.setCurrentTileIndex(MathUtils.random(0, pItem.getTileCount() - 1));
关于java - 带有 Sprite 表的 ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12202393/