Недостаточно памяти. InflateException Двоичный XML-файл Android

У меня OutOfMemoryError при создании макета с несколькими изображениями.

В строке, где logcat показывает мне ошибку, я начинаю объявлять TextView.

Ошибка на Samsung Galaxy S4. Когда я запускаю приложения в HTC Desire X, ошибки не возникает.

Что может быть причиной этого и как я могу это исправить.

10-21 18:32:19.243: E/dalvikvm-heap(20015): Out of memory on a 15822016-byte allocation.
10-21 18:32:19.243: I/dalvikvm(20015): "main" prio=5 tid=1 RUNNABLE
10-21 18:32:19.243: I/dalvikvm(20015):   | group="main" sCount=0 dsCount=0 obj=0x41d6cea0 self=0x41d5b538
10-21 18:32:19.243: I/dalvikvm(20015):   | sysTid=20015 nice=0 sched=0/0 cgrp=apps handle=1074303316
10-21 18:32:19.243: I/dalvikvm(20015):   | state=R schedstat=( 0 0 0 ) utm=235 stm=203 core=2
10-21 18:32:19.243: I/dalvikvm(20015):   at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-21 18:32:19.243: I/dalvikvm(20015):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
10-21 18:32:19.243: I/dalvikvm(20015):   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
10-21 18:32:19.243: I/dalvikvm(20015):   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
10-21 18:32:19.243: I/dalvikvm(20015):   at android.content.res.Resources.loadDrawable(Resources.java:3056)
10-21 18:32:19.243: I/dalvikvm(20015):   at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
10-21 18:32:19.253: I/dalvikvm(20015):   at android.view.View.<init>(View.java:3694)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.widget.TextView.<init>(TextView.java:898)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.widget.TextView.<init>(TextView.java:893)
10-21 18:32:19.263: I/dalvikvm(20015):   at java.lang.reflect.Constructor.constructNative(Native Method)
10-21 18:32:19.263: I/dalvikvm(20015):   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.view.LayoutInflater.createView(LayoutInflater.java:600)
10-21 18:32:19.263: I/dalvikvm(20015):   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
10-21 18:32:19.263: I/dalvikvm(20015):   at com.example.fragments.LocalApiFragment.onCreateView(LocalApiFragment.java:40)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.os.Handler.handleCallback(Handler.java:733)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.os.Handler.dispatchMessage(Handler.java:95)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.os.Looper.loop(Looper.java:157)
10-21 18:32:19.263: I/dalvikvm(20015):   at android.app.ActivityThread.main(ActivityThread.java:5356)
10-21 18:32:19.263: I/dalvikvm(20015):   at java.lang.reflect.Method.invokeNative(Native Method)
10-21 18:32:19.263: I/dalvikvm(20015):   at java.lang.reflect.Method.invoke(Method.java:515)
10-21 18:32:19.263: I/dalvikvm(20015):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
10-21 18:32:19.263: I/dalvikvm(20015):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
10-21 18:32:19.263: I/dalvikvm(20015):   at dalvik.system.NativeStart.main(Native Method)
10-21 18:32:19.263: D/skia(20015): --- allocation failed for scaled bitmap
10-21 18:32:19.263: D/AndroidRuntime(20015): Shutting down VM
10-21 18:32:19.263: W/dalvikvm(20015): threadid=1: thread exiting with uncaught exception (group=0x41d6bda0)
10-21 18:32:19.263: E/AndroidRuntime(20015): FATAL EXCEPTION: main
10-21 18:32:19.263: E/AndroidRuntime(20015): Process: com.example, PID: 20015
10-21 18:32:19.263: E/AndroidRuntime(20015): android.view.InflateException: Binary XML file line #36: Error inflating class <unknown>
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.LayoutInflater.createView(LayoutInflater.java:626)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at com.example.fragments.LocalApiFragment.onCreateView(LocalApiFragment.java:40)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.os.Handler.handleCallback(Handler.java:733)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.os.Handler.dispatchMessage(Handler.java:95)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.os.Looper.loop(Looper.java:157)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.app.ActivityThread.main(ActivityThread.java:5356)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at java.lang.reflect.Method.invokeNative(Native Method)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at java.lang.reflect.Method.invoke(Method.java:515)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at dalvik.system.NativeStart.main(Native Method)
10-21 18:32:19.263: E/AndroidRuntime(20015): Caused by: java.lang.reflect.InvocationTargetException
10-21 18:32:19.263: E/AndroidRuntime(20015):    at java.lang.reflect.Constructor.constructNative(Native Method)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.LayoutInflater.createView(LayoutInflater.java:600)
10-21 18:32:19.263: E/AndroidRuntime(20015):    ... 23 more
10-21 18:32:19.263: E/AndroidRuntime(20015): Caused by: java.lang.OutOfMemoryError
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.content.res.Resources.loadDrawable(Resources.java:3056)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.view.View.<init>(View.java:3694)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.widget.TextView.<init>(TextView.java:898)
10-21 18:32:19.263: E/AndroidRuntime(20015):    at android.widget.TextView.<init>(TextView.java:893)
10-21 18:32:19.263: E/AndroidRuntime(20015):    ... 26 more

2 ответа

Ваше растровое изображение слишком тяжелое. Измените его размер (например, gimp) и попробуйте снова.

Я сталкиваюсь с этой проблемой и в большинстве устройств HiDef, таких как Galaxy S4. Это связано с тем, что устройства HiDef используют xhdpi, xxhdpi и т. Д. Для раздувания нарисованного. Когда они не находят это, они масштабируют это программно, таким образом вызывая Исключение OutOfMemory. Таким образом, решение состоит в том, чтобы поместить ваш drawable в эти папки hdpi, xhdpi, xxhdpi, xxhdpi соответственно.

Samsung Helpdesk источник

Другие вопросы по тегам