android.view.InflateException:二进制XML文件行#8

时间:2014-01-01 22:43:24

标签: android xml android-activity crash

从我可以收集的程序已被放入后台Application Stop已被调用。应用程序返回到forground,这是发生错误的时候。该应用程序因任何原因无法加载xml文件,每次在我的手机HTC Desire One上运行代码和xml。有什么明显的东西我可以解决这个问题,或者有关如何追踪这个问题的任何建议?

这是我从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)

这是xml文件

<?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>

代码

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);
    }
}

1 个答案:

答案 0 :(得分:15)

这些堆栈报告是OutOfMemory异常,即设备内存不足。

检查放置背景图像的可绘制目录,对于768x1280像素,它应该是drawable-xhdpi。 Android会自动缩放其他屏幕尺寸的图像,这意味着如果您将图像放在drawable-mdpi中,对于xxhdpi设备(例如Samsung 4),它将缩放到2304x3840。

请注意,建议为每个支持的屏幕大小提供位图资源。有关支持多种屏幕尺寸的详情,请参阅http://developer.android.com/guide/practices/screens_support.html

除此之外,除了在setContentView上使用try子句捕获异常并正常处理它之外,您几乎无法对OutOfMemoryException执行此操作。有一些非常糟糕的Android设备存在内存问题。您应该将应用程序连接到更好的错误报告系统,在那里获得更多设备数据,以确认是这种情况。