如何在android中解决java.lang.OutOfMemory异常?

时间:2015-02-22 18:24:14

标签: java android android-studio

02-22 23:37:03.349    1845-1845/com.vinay.vshotelapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.vinay.vshotelapplication, PID: 1845
    java.lang.OutOfMemoryError: Failed to allocate a 4801692 byte allocation with 1152928 free bytes and 1125KB until OOM
            at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
            at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
            at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
            at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
            at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:973)
            at android.content.res.Resources.loadDrawableForCookie(Resources.java:2423)
            at android.content.res.Resources.loadDrawable(Resources.java:2330)
            at android.content.res.Resources.getDrawable(Resources.java:758)
            at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:319)
            at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1095)
            at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1017)
            at android.content.res.Resources.loadDrawableForCookie(Resources.java:2418)
            at android.content.res.Resources.loadDrawable(Resources.java:2330)
            at android.content.res.Resources.getDrawable(Resources.java:758)
            at android.content.Context.getDrawable(Context.java:402)
            at android.view.View.setBackgroundResource(View.java:16106)
            at com.vinay.vshotelapplication.VSHotelApplicationMainActivity.onCreate(VSHotelApplicationMainActivity.java:53)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-22 23:37:37.774    1845-1845/com.vinay.vshotelapplication I/Process﹕ Sending signal. PID: 1845 SIG: 9
02-22 23:39:58.136    2323-2323/com.vinay.vshotelapplication I/Process﹕ Sending signal. PID: 2323 SIG: 9

1 个答案:

答案 0 :(得分:0)

我们需要代码才能看到确切的错误索引,但我猜您在代码上有非常高分辨率的图片。与5000 * 1419图片相同的错误,并将分辨率降低到500 * 142,所以1/100的内存再次释放。