我收到一些奇怪的错误,导致我的 android 应用程序崩溃。它是一个测验应用程序。因此,当用户正确回答 2/3 问题时,然后单击下一个按钮,它会崩溃。并显示索引 13 错误。但我不知道在哪里修复/寻找。这是我的代码片段。
public Vector<Sprite> defaultTile;
private void GameResults()
{
if(result.equals("right"))
{
GameOver();
Log.e("Gaa", "Right Here ->");
}
}
private void GameOver() {
{
for (int i = 0; i < defaultTile.size(); i++) {
defaultTile.get(i).setVisible(false);
}
for (int i = 0; i < defaultTile.size(); i++)
{
unregisterTouchArea(defaultTile.get(i));
}
questionText.detachSelf();
}
@Override
public boolean onAreaTouched(TouchEvent event, ITouchArea area, float posX,
float posY) {
if(event.isActionUp())
{
if(area instanceof Sprite)
{
Sprite sprite = (Sprite)area;
int userData = (Integer) sprite.getUserData();
switch(userData)
{
case BTN_NEXT:
if(gameState.equals("alpha") && tickBg.isVisible())
{
countdown.cancel();
GameResults();
}
break;
}
}
}
}
日志猫的详细信息是这样的
08-09 13:30:50.246: W/dalvikvm(919): threadid=12: thread exiting with uncaught exception (group=0x409c01f8)
08-09 13:30:50.276: E/AndroidRuntime(919): FATAL EXCEPTION: GLThread
08-09 13:30:50.276: E/AndroidRuntime(919): java.lang.IndexOutOfBoundsException: Invalid index 9, size is 9
08-09 13:30:50.276: E/AndroidRuntime(919): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
08-09 13:30:50.276: E/AndroidRuntime(919): at java.util.ArrayList.get(ArrayList.java:304)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.Entity.onManagedDrawChildren(Entity.java:1008)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.Entity.onDrawChildren(Entity.java:1000)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.Entity.onManagedDraw(Entity.java:993)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.shape.Shape.onManagedDraw(Shape.java:120)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.Entity.onDraw(Entity.java:875)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.Entity.onManagedDrawChildren(Entity.java:1008)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.Entity.onDrawChildren(Entity.java:1000)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.Entity.onManagedDraw(Entity.java:993)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.scene.Scene.onManagedDraw(Scene.java:233)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.entity.Entity.onDraw(Entity.java:875)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.engine.Engine.onDrawScene(Engine.java:517)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.engine.Engine.onDrawFrame(Engine.java:509)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.opengl.view.RenderSurfaceView$Renderer.onDrawFrame(RenderSurfaceView.java:154)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.opengl.view.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:617)
08-09 13:30:50.276: E/AndroidRuntime(919): at org.anddev.andengine.opengl.view.GLSurfaceView$GLThread.run(GLSurfaceView.java:549)
更新