我正在尝试为我的游戏制作在线排行榜。服务器端部分没问题,它在桌面版游戏中运行良好。
然而,在Android上它没有任何警告就崩溃了。要获取排行榜数据,我使用HTTPUrlConnection请求,然后使用LibsonDZ的JsonReader类解析数据。
当我解析数据时,这个函数
private void updateHighscoresTable(JsonValue value) {
int count = value.getInt("count");
for (int i = 0; i < 12; i++) {
JsonValue child = value.get("" + i);
String nickname = child.getString("nickname");
int score = child.getInt("score");
highscoresScreen.highscoresTable.center();
highscoresScreen.highscoresTable.add(nickname).width(getCellWidth());
highscoresScreen.highscoresTable.add("" + score);
highscoresScreen.highscoresTable.row();
}
highscoresScreen.highscoresTable.setVisible(true);
}
在highscores表中插入所有内容。该表通过ScrollPane在屏幕上绘制。 当有超过12个对象时,游戏将在表格出现之前立即崩溃。
这是初始化Table和ScrollPane的代码
highscoresTable = new Table(skin);
highscoresTable.setSize(460, 240);
highscoresScrollPane = new ScrollPane(highscoresTable);
highscoresScrollPane.setBounds(10, 40, 460, 240);
highscoresScrollPane.setFadeScrollBars(false);
highscoresTable.setVisible(false);
如果我在创建表后立即尝试添加50个元素,删除前一个函数中的for循环,它不会崩溃,但对我来说没用。 解析它的JSON没关系,我在for循环中添加了System.out.println,一切都正确。
我正在使用2014年2月14日的夜间版本。
答案 0 :(得分:0)
问题是我只将highscoresTable设置为隐藏,而我应该将highscoresScrollPane设置为隐藏!
所以:
highscoresScrollPane.setVisible(false)
解决了这个问题。