我做了一些研究,但没有运气 - 特别是因为大多数答案都与VM有关。我在手机上测试我的应用程序 - 三星Galaxy S4。我的应用程序崩溃,在菜单屏幕加载之前......出现以下错误。我不明白为什么因为我没有任何大图像(我检查过..我最大的png文件只有224 KB)。
任何idead如何修复?提前谢谢......
03-07 10:19:56.199 18473-18493/com.packtpub.libgdx.outtacluck.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 7662
Process: com.packtpub.libgdx.outtacluck.android, PID: 18473
java.lang.OutOfMemoryError: Failed to allocate a 103059952 byte allocation with 16777216 free bytes and 45MB until OOM
at java.util.ArrayList.add(ArrayList.java:118)
at com.packtpub.libgdx.outtacluck.screens.MenuScreen.buildScoresWindowLayer(MenuScreen.java:499)
at com.packtpub.libgdx.outtacluck.screens.MenuScreen.rebuildStage(MenuScreen.java:152)
at com.packtpub.libgdx.outtacluck.screens.MenuScreen.show(MenuScreen.java:128)
at com.packtpub.libgdx.outtacluck.screens.DirectedGame.setScreen(DirectedGame.java:51)
at com.packtpub.libgdx.outtacluck.ChickenMain.create(ChickenMain.java:51)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
这是触发错误的函数:
private Table buildScoresWindowLayer() {
scores = new Window("Top 5 High Scores", skinLibgdx);
FileHandle file = Gdx.files.internal("data/highscores.txt");
BufferedReader reader = new BufferedReader(file.reader());
ArrayList<String> lines = new ArrayList<String>();
String line = null;
try {
line = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
while (line != null){
lines.add(line);
}
scores.add(lines.get(0));
scores.add(lines.get(0));
scores.add(lines.get(0));
scores.add(lines.get(0));
scores.add(lines.get(0));
// + Character Skin: Selection Box (White, Gray, Brown)
//scores.add(buildOptWinSkinSelection()).row();
// + Debug: Show FPS Counter
//scores.add(buildOptWinDebug()).row();
// + Separator and Buttons (Save, Cancel)
scores.add(buildScoresWinButtons()).pad(10, 0, 10, 0);
// Make options window slightly transparent
scores.setColor(1, 1, 1, 0.8f);
// Hide options window by default
showScoresWindow(false, false);
if (debugEnabled)
scores.debug();
// Let TableLayout recalculate widget sizes and positions
scores.pack();
// Move options window to bottom right corner
scores.setPosition(Constants.VIEWPORT_GUI_WIDTH - scores.getWidth() - 150, 50);
return scores;
}
答案 0 :(得分:1)
你的while循环永无止境!得出结论;)