2016-12-14 54 views
-3

我正在爲我的拼貼項目開發一個小遊戲應用程序。當我在第一輪和第二輪時,我的應用程序運行順利的那一刻,它隨着此錯誤java.lang.OutofMemoryError崩潰。我找不到這個問題。java.lang.OutofMemoryError問題

if (pic == null) 
    pic = BitmapFactory.decodeResource(context.getResources(), R.drawable.background); 
scalepic = Bitmap.createScaledBitmap(pic, 720, 3840, false); 
pic.recycle(); 
background = new Background(scalepic); 

,這是錯誤:

java.lang.OutOfMemoryError: Failed to allocate a 117964812 byte allocation with 16777216 free bytes and 18MB until OOM 
    at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:856) 
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:675) 
    at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:703) 
    at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:733) 
    at de.hs_kl.imst.gatav.runner.GameView.<init>(GameView.java:88) 
    at de.hs_kl.imst.gatav.runner.Start.onCreate(Start.java:39) 
    at android.app.Activity.performCreate(Activity.java:6876) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
    at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:158) 
    at android.app.ActivityThread.main(ActivityThread.java:7229) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

如果我擦除循環,那麼遊戲的第一次嘗試後粉碎......

+0

@njumuralidharan請停止將logcatlogs從代碼更改爲blockqoute ...我知道你是聲望wh *但不是 – Selvin

+0

那麼每次開始新遊戲時都不要創建位圖 – EpicPandaForce

+0

@EpicPandaForce是啊,但我該怎麼做? – Penrock

回答

0

你可以調用System.gc();方法調用垃圾收集器如你所願。

相關問題