Search code examples
androidxmlinflate-exception

Android view.InflateException Binary XML


I realize that there are others with similar questions, but I've checked those and this is different. Also, I had no issues until I recently updated my SDK to Android 4.4, but it didn't seem to happen immediately after.

Here is my error on this Button in my XML:

  <Button
                    android:id="@+id/btnBodyfat"
                    android:layout_width="85dp"
                    android:layout_height="85dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:layout_weight="1"
                    android:background="@drawable/bodyfat_circle_button"
                    android:gravity="center_horizontal|center_vertical"
                    android:text="15%"
                    android:textSize="14sp" />

Here is my drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/circle_pressed" android:state_pressed="true"></item>
    <item android:drawable="@drawable/bodyfat_circle" android:state_focused="true"></item>
    <item android:state_enabled="false" android:drawable="@drawable/bodyfat_circle_disabled" />
    <item android:drawable="@drawable/bodyfat_circle"></item>
</selector>

Logcat:

   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zen.bodybuildingdiet/com.zen.bodybuildingdiet.InitialMainActivity}: android.view.InflateException: Binary XML file line #55: Error inflating class <unknown>
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
    08-19 20:36:35.912: E/AndroidRuntime(13717):    at       android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:269)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.app.Activity.setContentView(Activity.java:1885)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at com.janzen.bodybuildingdiet.InitialMainActivity.onCreate(InitialMainActivity.java:32)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.app.Activity.performCreate(Activity.java:4531)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
08-19 20:36:35.912: E/AndroidRuntime(13717):    ... 11 more
08-19 20:36:35.912: E/AndroidRuntime(13717): Caused by: java.lang.reflect.InvocationTargetException
08-19 20:36:35.912: E/AndroidRuntime(13717):    at java.lang.reflect.Constructor.constructNative(Native Method)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.view.LayoutInflater.createView(LayoutInflater.java:586)
08-19 20:36:35.912: E/AndroidRuntime(13717):    ... 24 more
08-19 20:36:35.912: E/AndroidRuntime(13717): Caused by: java.lang.OutOfMemoryError: (Heap Size=49187KB, Allocated=43342KB)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.graphics.Bitmap.nativeCreateScaledBitmap(Native Method)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:744)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:766)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:492)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.content.res.Resources.loadDrawable(Resources.java:2051)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.widget.ImageView.<init>(ImageView.java:119)
08-19 20:36:35.912: E/AndroidRuntime(13717):    at android.widget.ImageView.<init>(ImageView.java:109)
08-19 20:36:35.912: E/AndroidRuntime(13717):    ... 27 more
08-19 20:36:35.932: E/EmbeddedLogger(1754): App crashed! Process: com.janzen.bodybuildingdiet
08-19 20:36:36.082: E/EmbeddedLogger(1754): App crashed! Package: com.janzen.bodybuildingdiet v41 (2.0.2)
08-19 20:36:36.082: E/EmbeddedLogger(1754): Application Label: BB Diet
08-19 20:36:46.883: E/SurfaceTexture(1611): [Starting com.janzen.bodybuildingdiet] abandon: SurfaceTexture(0x0x1762600) has been abandoned!

Solution

  • your error is java.lang.OutOfMemoryError

    you are using a very large image in imageView or background of your button, you should decode it in a proper way , look at http://developer.android.com/training/displaying-bitmaps/ and http://developer.android.com/training/displaying-bitmaps/load-bitmap.html those links explain completely how to decode large images and show them on imageViews. for each image that you are using for example for background or capturing photo by camera or .... check the size and be sure it is not large , if it is , this nasty error will come to your app. (always post complete logcat :-)