InflateException: Binary XML file line #1: Error inflating class <unknown> caused by OutOfMemoryError

心不动则不痛 提交于 2019-11-26 18:53:08

Check your drawable/background_main i.e. the background image of your root layout - the VM runs out of memory when decoding the bitmap. Make the image dimensions smaller.

The problem occurs because the *drawable/background_main* has a high resolution image. So when it loads then the VM runs out of memory .

So best way is to reduce it size or resolution.

You are using this layout in fragment not in Activity.And also there is another exception OutOfMemory your background image is very large try to reduce it..

M D

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget may be the real culprit here. Try using smaller image to see if it is a memory-related issue. Check out these links for examples of similar issues:

java.lang.OutOfMemoryError: bitmap size exceeds VM budget - android - how many images? and OutOfMemory exception when loading bitmap from external storage

My problem was that I had a shape with a <solid> with color ?selectableItemBackground. Yes it is dumb and a specific case, but posting it here for people with the same mistake.

I've solved the same problem by reducing dimension of .png buttons in all xml files

Try using images of different resolutions such as mdpi,hdpi,xhdpi if only using higher resolution images it might cause a crash in low resolution phones

Well, in my case the answer was in xml design, conflict android:backgroundTint and android:tint

I was design a FloatinActionButton like this:

<android.support.design.widget.FloatingActionButton
                    android:id="@+id/fa_close_patient"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:scaleX="0.8"
                    android:scaleY="0.8"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_gravity="right"
                    android:layout_marginEnd="30dp"
                    android:backgroundTint="@color/white"
                    android:src="@drawable/ic_close_black_24dp"
                    android:tint="@color/colorPrimaryDark" />

and it's ok but API > 23

If u design for API_LEVEL < 23, this it's the fix

<android.support.design.widget.FloatingActionButton
                    android:id="@+id/fa_close_patient"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:scaleX="0.8"
                    android:scaleY="0.8"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_gravity="right"
                    android:layout_marginEnd="30dp"
                    app:backgroundTint="@color/white"
                    android:src="@drawable/ic_close_black_24dp"/>

I hope I have help you,

Regards

In my case I was getting illogical class inflation exceptions, after digging for a while I found that the error was caused due to deprecated code blocks related to android framework itself.

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