Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Andengine text indexoutofbounds异常_Android_Andengine - Fatal编程技术网

Android Andengine text indexoutofbounds异常

Android Andengine text indexoutofbounds异常,android,andengine,Android,Andengine,我正在用andengine编程一个游戏,我正在使用andengine文本显示高分 这就是代码: StrokeFont mFont = FontFactory.createStrokeFromAsset(this.getFontManager(), mainFontTexture, this.getAssets(), "Roboto-BoldItalic.ttf", 100, true, Color.WHITE, 2, Color.BLACK); mFont.load(); text_score

我正在用andengine编程一个游戏,我正在使用andengine文本显示高分

这就是代码:

StrokeFont mFont = FontFactory.createStrokeFromAsset(this.getFontManager(), mainFontTexture, this.getAssets(), "Roboto-BoldItalic.ttf", 100, true, Color.WHITE, 2, Color.BLACK);
mFont.load();

text_score_menu = new Text(25, 25, mFont, "Score: ",getVertexBufferObjectManager());


if(LC.Score>Constants.highScore){
     prefs.edit().putInt("highScore",LC.Score).commit();
     text_score_menu.setText("New High: " + LC.Score);
}else{
     text_score_menu.setText("Score: " + LC.Score);
}
问题是,当出现新的高分时,我正好在这里得到一个新的例外:

text_score_menu.setText("New High: " + LC.Score);
但我没有这个问题,当分数不是新的高分和分数显示

text_score_menu.setText("Score: " + LC.Score);
以下是错误消息:

FATAL EXCEPTION: UpdateThread
    java.lang.ArrayIndexOutOfBoundsException: length=210; index=210
            at org.andengine.entity.text.vbo.HighPerformanceTextVertexBufferObject.onUpdateVertices(HighPerformanceTextVertexBufferObject.java:121)
            at org.andengine.entity.text.Text.onUpdateVertices(Text.java:335)
            at org.andengine.entity.text.Text.setText(Text.java:223)

这是AndEngine中文本的一个常见陷阱-当您实例化text_score_菜单实体时,您将设置最大长度。试着改变这个

text\u score\u菜单=新文本(25,25,mFont,“score:”,getVertexBufferObjectManager())

text_score_menu=新文本(25,25,mFont,“新高:123456789”,getVertexBufferObjectManager())


这将建立一个足够长的文本字段-然后确保在显示实体之前“设置”正确的文本-(正如您在展示的代码中所做的那样)

长度为210。索引从0开始。所以数组没有一个元素@index 210。我知道。。。但我和长度无关。我只是想显示一个文本“New High:8”。这不是210个字符,但你的stacktrace暗示了我刚才提到的。什么是
LC.Score
?LC.Score是当前的分数,它是一个整数,最多2位数。OK我自己找到了答案。。。这与初始化有关。这里是我如何初始化文本的。“分数:”所以这里以某种方式定义了最大字符数,当我试图显示“新高:8”时,它太长了。相反,我做了不同的初始化(有很多空白)“分数:……”,效果很好:)对不起,我不熟悉评论格式我们同时找到了答案。。无论如何,谢谢你:)