2016-12-14 58 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();方法调用垃圾收集器如你所愿。

相关问题