Out of Memory : android.support.v7.app.AppCompatActivity.onCreate

末鹿安然 提交于 2019-12-04 07:28:12

问题


we recently switched to using AppCompatActivity instead of FragmentActivity and now some devices are randomly crashing with the following error. No idea why this is happening.

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 16008012 byte allocation with 4277152 free bytes and 4MB until OOM
   at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
   at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
   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 android.graphics.drawable.BitmapDrawable.updateStateFromTypedArray(BitmapDrawable.java:779)
   at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:741)
   at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:2549)
   at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:254)
   at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:164)
   at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:2549)
   at android.graphics.drawable.Drawable.createFromXml(Drawable.java:2320)
   at android.content.res.Resources.loadDrawableForCookie(Resources.java:4210)
   at android.content.res.Resources.loadDrawable(Resources.java:4089)
   at android.content.res.Resources.getDrawable(Resources.java:2005)
   at android.content.res.Resources.getDrawable(Resources.java:1987)
   at android.content.Context.getDrawable(Context.java:464)
   at android.support.v4.content.ContextCompat.android.support.v4.content.ContextCompatApi21.getDrawable(SourceFile:3026)
   at android.support.v7.widget.AppCompatDrawableManager.getDrawable(SourceFile:200)
   at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(SourceFile:81)
   at android.support.v7.app.AppCompatDelegateImplBase.(SourceFile:127)
   at android.support.v7.app.AppCompatDelegateImplV9.(SourceFile:147)
   at android.support.v7.app.AppCompatDelegateImplV11.(SourceFile:27)
   at android.support.v7.app.AppCompatDelegateImplV14.(SourceFile:53)
   at android.support.v7.app.AppCompatDelegateImplV23.(SourceFile:29)
   at android.support.v7.app.AppCompatDelegate.create(SourceFile:203)
   at android.support.v7.app.AppCompatDelegate.create(SourceFile:185)
   at android.support.v7.app.AppCompatActivity.getDelegate(SourceFile:525)
   at android.support.v7.app.AppCompatActivity.onCreate(SourceFile:74)
   at com.dubizzle.horizontal.activities.AbstractActivity.onCreate(SourceFile:98)
   at com.dubizzle.horizontal.activities.ItemPhotoViewer.onCreate(SourceFile:68)
   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(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

回答1:


You are trying to load an image using the BitmapFactory right?

I assume that your image is too big:

16008012 byte allocation with 4277152 free bytes and 4MB until OOM

Your image is 16008012 but you only have 4277152 bytes free. Try using a smaller image.




回答2:


This happened to me when I set a rather large drawable as the windowBackground property of the activity's theme. Reducing the size of the image should fix it



来源:https://stackoverflow.com/questions/41444321/out-of-memory-android-support-v7-app-appcompatactivity-oncreate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!