2016-03-07 85 views
-3

我已經做了一些研究,但沒有任何運氣 - 尤其是因爲大多數答案都與虛擬機有關。我正在物理手機上測試我的應用 - 三星Galaxy S4。在菜單屏幕加載之前,我的應用程序崩潰了,出現下面的錯誤。我不明白爲什麼,因爲我沒有任何大的圖像(我檢查了我的最大PNG文件只有224 KB)。java.lang.OutOfMemoryError:未能分配103059952字節分配,16777216空閒字節和45MB,直到OOM

任何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; 
} 
+7

'while(line!= null){lines.add(line); }這是否應該結束? – Hacketo

回答

1

while循環是永無止境!帶上它的結論;)

相關問題