Google Play控制台崩溃报告java.lang.OutOfMemoryError

时间:2018-02-08 13:08:44

标签: android

我在此设备上的Google Play控制台上收到了崩溃报告:Samsung Galaxy A5(2016)(a5xelte),

java.lang.OutOfMemoryError: 

  at dalvik.system.VMRuntime.newNonMovableArray (Native Method)

  at android.graphics.BitmapFactory.nativeDecodeAsset (Native Method)

  at android.graphics.BitmapFactory.decodeStream (BitmapFactory.java:700)

  at android.graphics.BitmapFactory.decodeResourceStream (BitmapFactory.java:535)

  at android.graphics.drawable.Drawable.createFromResourceStream (Drawable.java:1179)

  at android.content.res.ResourcesImpl.loadDrawableForCookie (ResourcesImpl.java:770)

  at android.content.res.ResourcesImpl.loadDrawable (ResourcesImpl.java:621)

  at android.content.res.Resources.loadDrawable (Resources.java:1729)

  at android.content.res.TypedArray.getDrawable (TypedArray.java:945)

  at android.widget.ImageView.<init> (ImageView.java:157)

  at android.widget.ImageView.<init> (ImageView.java:145)

  at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:60)

  at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:56)

  at android.support.v7.internal.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:98)

  at android.support.v7.app.AppCompatDelegateImplV7.createView (AppCompatDelegateImplV7.java:926)

  at android.support.v7.app.AppCompatDelegateImplV7.onCreateView (AppCompatDelegateImplV7.java:980)

  at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView (LayoutInflaterCompatHC.java:44)

  at android.view.LayoutInflater$FactoryMerger.onCreateView (LayoutInflater.java:193)

  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:776)

  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:734)

  at android.view.LayoutInflater.rInflate (LayoutInflater.java:865)

  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:828)

  at android.view.LayoutInflater.rInflate (LayoutInflater.java:873)

  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:828)

  at android.view.LayoutInflater.rInflate (LayoutInflater.java:873)

  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:828)

  at android.view.LayoutInflater.rInflate (LayoutInflater.java:873)

  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:828)

  at android.view.LayoutInflater.inflate (LayoutInflater.java:525)

  at android.view.LayoutInflater.inflate (LayoutInflater.java:427)

  at package.Accueil.onCreateView (Accueil.java:75)

  at android.support.v4.app.Fragment.performCreateView (Fragment.java:1965)

  at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1078)

  at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1259)

  at android.support.v4.app.BackStackRecord.run (BackStackRecord.java:738)

  at android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1624)

  at android.support.v4.app.FragmentController.execPendingActions (FragmentController.java:330)

  at android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:547)

  at android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1256)

  at android.app.Activity.performStart (Activity.java:6972)

  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2937)

  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)

  at android.app.ActivityThread.-wrap14 (ActivityThread.java)

  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1642)

  at android.os.Handler.dispatchMessage (Handler.java:102)

  at android.os.Looper.loop (Looper.java:154)

  at android.app.ActivityThread.main (ActivityThread.java:6776)

  at java.lang.reflect.Method.invoke (Native Method)

  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1496)

  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)

坠机线: at package.Accueil.onCreateView(Accueil.java:75)

这是一个:

TextView textView = (TextView) getActivity().findViewById(R.id.main_toolbar_title);

我不明白应用程序如何在此行崩溃。我在谷歌搜索他们谈论要加载的大文件......

以下是我的所有标准:

enter image description here

观点:

enter image description here

我认为问题在于我的绘图和图像的密度,我没有理解这一点:我提出了一个问题:

Understanding Drawables and Images sizes

我不知道我是否拥有所有屏幕尺寸。

3 个答案:

答案 0 :(得分:1)

OOME在实例化你的布局(尤其是图像)时出现 - 也许有一些不好的位图太大了?也许你的布局太复杂了?

答案 1 :(得分:1)

OOM通常与一个地方无关。尽管崩溃发生在package.Accueil.onCreateView(Accueil.java:75),但很可能不是因为它造成的。根据我的经验,OOM是由比需要更大的图像引起的。

如果您从某个服务器下载图像,请使用Glide来获取它,因为即使在调整大小之前实际图像的大小,它也只会保留适合您视图的已调整大小的图像。 检查Glide和Picasso之间的比较:https://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

您可能还会使用LeakCanary检查内存泄漏,但我首先会使用图像。

答案 2 :(得分:0)

您的问题是,当执行此行时,平台会创建您的View heirarchy。您可能在视图中有很多大图像,因此您的应用程序必须分配大量内存来显示所有这些大图像。所以现在解决方案归结为你如何解决问题。您有两种选择:

  • 设计图像更少或更小
  • 让您的图片使用更少的内存

我建议做两件事。我不能建议你改进设计。但是为了减小尺寸,this section in the documentation is a good guide。它正在讨论网络传输,但也可能有助于你的APK。

There is also some good advice here