-2

I am developing an app, that has 13 fragments. I tested it on many virtual android devices and it crashes with the following exception only in Android Version 4.4.4 with resolution 1080x1920:

android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
        at android.view.LayoutInflater.createView(LayoutInflater.java:620)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        (...)
 Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at android.view.LayoutInflater.createView(LayoutInflater.java:594)
        at (...)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
        at (...)   //output is same like in the link with question below

all fragments have the same layout xml and on the second line it is a declaration of LienarLayout.

I have already read the questions like android.view.InflateException: Binary XML file line #2: Error inflating class <unknown> and all the images, that I use, are with resolution 720x1280 (xhdpi) and are loaded from the xml as background of the fragments, not as Bitmap or what else.

Here is the beginning of the layout xml file, where the line #2 is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:id="@+id/frg_bckg">

I have no real device with the same parameters to test it. Does anybody know what could be the reason for this exception and if it will appear on a real device too?

Thank you in advance!

3
  • Your post is close to unreadable, consider formatting it. :) also post your xml file Commented Aug 4, 2015 at 20:40
  • it can't load drawable. looks like it's huge ) Commented Aug 4, 2015 at 20:48
  • this is the 9th fragment (all fragments are with same structure and all other fragments don't throw any exception, that's why I'm wondering) and the drawable is 209KB with resolution 720x1280, I think it's not big Commented Aug 4, 2015 at 20:50

1 Answer 1

1

Does anybody know what could be the reason for this exception

You do not have a large enough block of free memory for the allocation, which appears to be being requested in support of loading a drawable resource.

the drawable is 209KB with resolution 720x1280, I think it's not big

That is 3,686,400 bytes (720 pixels x 1280 pixels x 4 bytes/pixel). Individually, that is pretty big. Having several of them can easily cause you to run out of heap space.

if it will appear on a real device too?

Probably. Each device has a Dalvik heap limit for apps running on that device. It could be as low as 16MB, though values in the 24-48MB range are more common.

Dealing with larger bitmaps in Android is tricky business.

Sign up to request clarification or add additional context in comments.

3 Comments

okay, but if 209KB is large, what about 1MB... For example games like FIFA for phone etc, that are bigger than 300MB at all should have larger images and don't get OutOfMemory and secondly - I tried the app on Android version 4.1.1, 4.3, 4.4.2 and 5.0 and all of them are okay + 4.4.4 with resolution 800x1280 is okay too (Google Nexus 7) I get an error only on devices with android version 4.4.4 and resolution bigger than 800x1280...
@GabriellaAngelova: "but if 209KB is large, what about 1MB" -- you will notice that my answer did not mention 209KB. That is because the size of the disk file does not matter much. The size of the memory allocation is what matters. That is based solely on resolution and bit depth. "For example games like FIFA for phone" -- generally speaking, they are not developed in Java and therefore are using other techniques overall.
aha, I understand the arithmetic with the resolution, but it's not possible to use only small (as resolution) pictures, because they look bad on big displays and it still be a mystery for me why do other devices have no problem with the pictures and only those with android version 4.4.4 and resolution bigger than 800x1280 (for example Samsung Galaxy S5 with android 4.4.4 or Google Nexus 5 with android 4.4.4 - same devices but with other android version are okay)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.