android.view.InflateException: Binary XML file line #8

android, android-activity, crash, xml

Solution

Those stack reports are OutOfMemory exceptions, i.e. the device is out of memory.

Check in which drawable directory you are placing the background image, for 768x1280 px it should be drawable-xhdpi. Android automatically scales the image for other screen sizes, which means that if you place the image in drawable-mdpi it will be scaled to 2304x3840 for xxhdpi devices such as the Samsung 4.

Note that it is recommended to provide a bitmap resource for each supported screen size. See more about supporting multiple screen sizes here http://developer.android.com/guide/practices/screens_support.html

Other than that there is little that you can do about OutOfMemoryException other than catching the exception with a try clause on setContentView and handling it gracefully. There are some really poor Android devices out there where memory problems are frequent. You should connect your App to a better error reporting system, where you get more device data, to confirm that this is the case.

Problem

From what I can gather the program has been put into the background Application Stop has been called. The application is brought back into the forground and this is when the error is occuring. The app is unable to load the xml file for whatever reason, the code and xml work everytime on my phone HTC Desire One. Is there anything obvious that I can look at to fix this, or any suggestions as to how to track down this problem? This is the call stack that I get back from TestFlight. ``` java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hdms.manager/com.hdms.manager.Drawable.SplashScreen}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown> android.app.ActivityThread.performLaunchActivity in ActivityThread.java on Line 2247 android.app.ActivityThread.handleLaunchActivity in ActivityThread.java on Line 2297 android.app.ActivityThread.access$700 in ActivityThread.java on Line 152 android.app.ActivityThread$H.handleMessage in ActivityThread.java on Line 1282 android.os.Handler.dispatchMessage in Handler.java on Line 99 android.os.Looper.loop in Looper.java on Line 137 android.app.ActivityThread.main in ActivityThread.java on Line 5328 java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke in Method.java on Line 511 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run in ZygoteInit.java on Line 1102 com.android.internal.os.ZygoteInit.main in ZygoteInit.java on Line 869 dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown> android.view.LayoutInflater.createView in LayoutInflater.java on Line 619 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView in PhoneLayoutInflater.java on Line 56 android.view.LayoutInflater.onCreateView in LayoutInflater.java on Line 666 android.view.LayoutInflater.createViewFromTag in LayoutInflater.java on Line 691 android.view.LayoutInflater.rInflate in LayoutInflater.java on Line 752 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 495 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 397 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 353 com.android.internal.policy.impl.PhoneWindow.setContentView in PhoneWindow.java on Line 327 android.app.Activity.setContentView in Activity.java on Line 1928 com.hdms.manager.Drawable.SplashScreen.onCreate in SplashScreen.java on Line 25 android.app.Activity.performCreate in Activity.java on Line 5250 android.app.Instrumentation.callActivityOnCreate in Instrumentation.java on Line 1097 android.app.ActivityThread.performLaunchActivity in ActivityThread.java on Line 2211 ... 11 more Caused by: java.lang.reflect.InvocationTargetException java.lang.reflect.Constructor.constructNative(Native Method) java.lang.reflect.Constructor.newInstance in Constructor.java on Line 417 android.view.LayoutInflater.createView in LayoutInflater.java on Line 593 ... 24 more Caused by: java.lang.OutOfMemoryError android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) android.graphics.BitmapFactory.decodeStream in BitmapFactory.java on Line 596 android.graphics.BitmapFactory.decodeResourceStream in BitmapFactory.java on Line 444 android.graphics.drawable.Drawable.createFromResourceStream in Drawable.java on Line 817 android.content.res.Resources.loadDrawable in Resources.java on Line 2854 android.content.res.TypedArray.getDrawable in TypedArray.java on Line 602 android.widget.ImageView.<init> in ImageView.java on Line 126 android.widget.ImageView.<init> in ImageView.java on Line 116 ... 27 more android.view.InflateException: Binary XML file line #8: Error inflating class <unknown> android.view.LayoutInflater.createView in LayoutInflater.java on Line 619 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView in PhoneLayoutInflater.java on Line 56 android.view.LayoutInflater.onCreateView in LayoutInflater.java on Line 666 android.view.LayoutInflater.createViewFromTag in LayoutInflater.java on Line 691 android.view.LayoutInflater.rInflate in LayoutInflater.java on Line 752 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 495 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 397 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 353 com.android.internal.policy.impl.PhoneWindow.setContentView in PhoneWindow.java on Line 327 android.app.Activity.setContentView in Activity.java on Line 1928 com.hdms.manager.Drawable.SplashScreen.onCreate in SplashScreen.java on Line 25 android.app.Activity.performCreate in Activity.java on Line 5250 android.app.Instrumentation.callActivityOnCreate in Instrumentation.java on Line 1097 android.app.ActivityThread.performLaunchActivity in ActivityThread.java on Line 2211 android.app.ActivityThread.handleLaunchActivity in ActivityThread.java on Line 2297 android.app.ActivityThread.access$700 in ActivityThread.java on Line 152 android.app.ActivityThread$H.handleMessage in ActivityThread.java on Line 1282 android.os.Handler.dispatchMessage in Handler.java on Line 99 android.os.Looper.loop in Looper.java on Line 137 android.app.ActivityThread.main in ActivityThread.java on Line 5328 java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke in Method.java on Line 511 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run in ZygoteInit.java on Line 1102 com.android.internal.os.ZygoteInit.main in ZygoteInit.java on Line 869 dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException java.lang.reflect.Constructor.constructNative(Native Method) java.lang.reflect.Constructor.newInstance in Constructor.java on Line 417 android.view.LayoutInflater.createView in LayoutInflater.java on Line 593 ... 24 more Caused by: java.lang.OutOfMemoryError android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) android.graphics.BitmapFactory.decodeStream in BitmapFactory.java on Line 596 android.graphics.BitmapFactory.decodeResourceStream in BitmapFactory.java on Line 444 android.graphics.drawable.Drawable.createFromResourceStream in Drawable.java on Line 817 android.content.res.Resources.loadDrawable in Resources.java on Line 2854 android.content.res.TypedArray.getDrawable in TypedArray.java on Line 602 android.widget.ImageView.<init> in ImageView.java on Line 126 android.widget.ImageView.<init> in ImageView.java on Line 116 ... 27 more java.lang.reflect.InvocationTargetException java.lang.reflect.Constructor.constructNative(Native Method) java.lang.reflect.Constructor.newInstance in Constructor.java on Line 417 android.view.LayoutInflater.createView in LayoutInflater.java on Line 593 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView in PhoneLayoutInflater.java on Line 56 android.view.LayoutInflater.onCreateView in LayoutInflater.java on Line 666 android.view.LayoutInflater.createViewFromTag in LayoutInflater.java on Line 691 android.view.LayoutInflater.rInflate in LayoutInflater.java on Line 752 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 495 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 397 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 353 com.android.internal.policy.impl.PhoneWindow.setContentView in PhoneWindow.java on Line 327 android.app.Activity.setContentView in Activity.java on Line 1928 com.hdms.manager.Drawable.SplashScreen.onCreate in SplashScreen.java on Line 25 android.app.Activity.performCreate in Activity.java on Line 5250 android.app.Instrumentation.callActivityOnCreate in Instrumentation.java on Line 1097 android.app.ActivityThread.performLaunchActivity in ActivityThread.java on Line 2211 android.app.ActivityThread.handleLaunchActivity in ActivityThread.java on Line 2297 android.app.ActivityThread.access$700 in ActivityThread.java on Line 152 android.app.ActivityThread$H.handleMessage in ActivityThread.java on Line 1282 android.os.Handler.dispatchMessage in Handler.java on Line 99 android.os.Looper.loop in Looper.java on Line 137 android.app.ActivityThread.main in ActivityThread.java on Line 5328 java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke in Method.java on Line 511 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run in ZygoteInit.java on Line 1102 com.android.internal.os.ZygoteInit.main in ZygoteInit.java on Line 869 dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.OutOfMemoryError android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) android.graphics.BitmapFactory.decodeStream in BitmapFactory.java on Line 596 android.graphics.BitmapFactory.decodeResourceStream in BitmapFactory.java on Line 444 android.graphics.drawable.Drawable.createFromResourceStream in Drawable.java on Line 817 android.content.res.Resources.loadDrawable in Resources.java on Line 2854 android.content.res.TypedArray.getDrawable in TypedArray.java on Line 602 android.widget.ImageView.<init> in ImageView.java on Line 126 android.widget.ImageView.<init> in ImageView.java on Line 116 ... 27 more java.lang.OutOfMemoryError android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) android.graphics.BitmapFactory.decodeStream in BitmapFactory.java on Line 596 android.graphics.BitmapFactory.decodeResourceStream in BitmapFactory.java on Line 444 android.graphics.drawable.Drawable.createFromResourceStream in Drawable.java on Line 817 android.content.res.Resources.loadDrawable in Resources.java on Line 2854 android.content.res.TypedArray.getDrawable in TypedArray.java on Line 602 android.widget.ImageView.<init> in ImageView.java on Line 126 android.widget.ImageView.<init> in ImageView.java on Line 116 java.lang.reflect.Constructor.constructNative(Native Method) java.lang.reflect.Constructor.newInstance in Constructor.java on Line 417 android.view.LayoutInflater.createView in LayoutInflater.java on Line 593 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView in PhoneLayoutInflater.java on Line 56 android.view.LayoutInflater.onCreateView in LayoutInflater.java on Line 666 android.view.LayoutInflater.createViewFromTag in LayoutInflater.java on Line 691 android.view.LayoutInflater.rInflate in LayoutInflater.java on Line 752 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 495 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 397 android.view.LayoutInflater.inflate in LayoutInflater.java on Line 353 com.android.internal.policy.impl.PhoneWindow.setContentView in PhoneWindow.java on Line 327 android.app.Activity.setContentView in Activity.java on Line 1928 com.hdms.manager.Drawable.SplashScreen.onCreate in SplashScreen.java on Line 25 android.app.Activity.performCreate in Activity.java on Line 5250 android.app.Instrumentation.callActivityOnCreate in Instrumentation.java on Line 1097 android.app.ActivityThread.performLaunchActivity in ActivityThread.java on Line 2211 android.app.ActivityThread.handleLaunchActivity in ActivityThread.java on Line 2297 android.app.ActivityThread.access$700 in ActivityThread.java on Line 152 android.app.ActivityThread$H.handleMessage in ActivityThread.java on Line 1282 android.os.Handler.dispatchMessage in Handler.java on Line 99 android.os.Looper.loop in Looper.java on Line 137 android.app.ActivityThread.main in ActivityThread.java on Line 5328 java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke in Method.java on Line 511 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run in ZygoteInit.java on Line 1102 com.android.internal.os.ZygoteInit.main in ZygoteInit.java on Line 869 dalvik.system.NativeStart.main(Native Method) ``` Here is the xml file ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView" android:src="@drawable/splash_image" android:layout_centerInParent="true" android:scaleType="centerCrop"/> <!--<VideoView android:layout_height="wrap_content"--> <!--android:layout_width="wrap_content"--> <!--android:id="@+id/videoView"/>--> </RelativeLayout> ``` And the code ``` package com.hdms.manager.Drawable; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import com.hdms.manager.MainActivity; import com.hdms.manager.R; /** * Created by bradj on 8/10/13. * */ public class SplashScreen extends Activity { // Splash screen timer private static final int mDisplaySplashScreen = 500; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); new Handler().postDelayed(new Runnable() { @Override public void run() { // This method will be executed once the timer is over // Start your app main activity Intent i = new Intent(SplashScreen.this, MainActivity.class); startActivity(i); // close this activity finish(); } }, mDisplaySplashScreen); } } ```

Original source