java.lang.OutOfMemoryError:未能分配6的11675148字节分配

时间:2018-07-05 14:23:43

标签: android dpi

有人能理解这个错误吗?这是在物理设备Android 6.0上进行的,但是在VD 5.0上可以正常使用。

这是错误

Process: com.example.ericr.pokerquizzer, PID: 10884
java.lang.OutOfMemoryError: Failed to allocate a 11675148 byte allocation with 6
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:44
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2638)
at android.content.res.Resources.loadDrawable(Resources.java:2543)
at android.content.res.Resources.getDrawable(Resources.java:806)
at android.content.Context.getDrawable(Context.java:458)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:3
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatD
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatD
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatRe
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppComp
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.ja
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.ja
at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatVie
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInfl
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelega
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDele
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDe
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity
at com.example.ericr.pokerquizzer.PlayActivity.onCreate(PlayActivity.java:37
at android.app.Activity.performCreate(Activity.java:6245)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:113
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)

                                                                                at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.jav
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

好吧,当我键入此内容时,我做了更多的研究,发现这个问题与图像密度有关?但是,我的应用程序在低密度平板电脑(Nexus 9)上运行正常,在高密度虚拟设备(Nexus 5)上运行,但是在中等密度的Moto G3(物理设备)上崩溃。

预先感谢

1 个答案:

答案 0 :(得分:1)

在将图像添加到android项目之前对其进行优化,您可以使用RIOT之类的免费软件来做到这一点,并且还要确保如果您通过url进行图像调用,它们始终是单例的