gpt4 book ai didi

android - java.lang.IndexOutOfBoundsException:无效的索引2,大小为2

转载 作者:行者123 更新时间:2023-12-03 17:44:32 24 4
gpt4 key购买 nike

在使用andengine开发的我的应用程序中,某些用户过于频繁地崩溃。
我没有分离/附加任何对象,但是仍然出现此错误。我正在使用对象可见性和unregistertoucharea,尽管我没有将其放到runonupdate中。会导致这个问题吗?如果不能,请告诉我可能如何?

这是我从Google Play获得的崩溃报告。

java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at org.andengine.c.a.d(Unknown Source)
at org.andengine.c.c.e.d(Unknown Source)
at org.andengine.c.a.a(Unknown Source)
at org.andengine.b.a.b(Unknown Source)
at org.andengine.b.a.a(Unknown Source)
at org.andengine.opengl.e.g.onDrawFrame(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

有时游戏在游戏结束时崩溃,有时在重新启动游戏时崩溃

游戏结束时,我正在调用以下函数
public void GameOver(){
yourScoreText.setText(""+score);
restart_button.setVisible(true);
leaderboard_button.setVisible(true);
share_button.setVisible(true);
gameOverText.setVisible(true);
gameOverOverlay.setVisible(true);
yourScoreText.setVisible(true);
highScoreText.setVisible(true);

this.registerTouchArea(restart_button);
this.registerTouchArea(leaderboard_button);
this.registerTouchArea(share_button);
}

当按下重启键时,我正在调用以下函数。
public void RestartGame(){
restart_button.setVisible(false);
leaderboard_button.setVisible(false);
share_button.setVisible(false);
gameOverText.setVisible(false);
gameOverOverlay.setVisible(false);
yourScoreText.setVisible(false);
highScoreText.setVisible(false);
this.unregisterTouchArea(restart_button);
this.unregisterTouchArea(leaderboard_button);
this.unregisterTouchArea(share_button);
score = 0;
scoreText.setText("Score: "+score);

Log.d("game start","game has been started");
StartScreen();
}
public void StartScreen(){
leaderboard_home_button.setVisible(true);
rate_button.setVisible(true);
if(activity.getNoAds()==0){
no_ads_button.setVisible(true);
this.registerTouchArea(no_ads_button);
}
if(isMute){
sound_off_button.setVisible(true);
this.registerTouchArea(sound_off_button);
} else {
sound_on_button.setVisible(true);
this.registerTouchArea(sound_on_button);
}
this.registerTouchArea(leaderboard_home_button);
this.registerTouchArea(rate_button);

}

最佳答案

数组索引从0开始计数。
因此,如果Array的大小= 2,则它们具有以下索引:0,1。因此,在这种情况下,索引号2不存在。

PS:如果您需要更多详细信息,请提供一些代码,我将编辑我的答案;)

关于android - java.lang.IndexOutOfBoundsException:无效的索引2,大小为2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26797183/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com