android.view.InflateException:二进制XML文件行#8:错误膨胀类android.widget.ImageView

时间:2017-09-13 22:42:14

标签: android layout android-inflate

我在android项目的xml文件中遇到以下错误。

  

android.view.InflateException:二进制XML文件行#8:错误膨胀类android.widget.ImageView

我已经看到this solution but can't understand/ it doesn't in my project. xml文件有问题吗?或者我是否需要处理活动文件?

我在添加自定义导航抽屉时收到错误。

这是错误

09-14 04:23:53.841 22880-22880/? E/AndroidRuntime: in writeCrashedAppName, pkgName :info.androidhive.navigationdrawer
09-14 04:23:53.851 22880-22880/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: info.androidhive.navigationdrawer, PID: 22880
java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.navigationdrawer/info.androidhive.navigationdrawer.activity.SplashScreen}: android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5021)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ImageView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1978)
at info.androidhive.navigationdrawer.activity.SplashScreen.onCreate(SplashScreen.java:14)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5021) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) 
at dalvik.system.NativeStart.main(Native Method) 
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 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290) 
at android.app.Activity.setContentView(Activity.java:1978) 
at info.androidhive.navigationdrawer.activity.SplashScreen.onCreate(SplashScreen.java:14) 
at android.app.Activity.performCreate(Activity.java:5426) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 

这是我的活动档案:

public class SplashScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);
        Thread myThread = new Thread(){
            @Override
            public void run() {
                try {
                    sleep(3000);
                    Intent intent = new Intent(getApplicationContext(),LoginActivity.class);
                    startActivity(intent);
                    finish();

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        myThread.start();
    }
}

这是我的启动画面的xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="info.androidhive.navigationdrawer.activity.SplashScreen">

    <ImageView
        android:id="@+id/pic_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ist_logo"
        android:layout_marginTop="50dp"
        android:layout_centerHorizontal="true"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="IST LIBRARY"
        android:textSize="30dp"
        android:layout_marginTop="200dp"
        android:layout_marginLeft="100dp"
        android:textStyle="bold"
        android:textColor="#000000"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Android Application"
        android:textSize="20dp"
        android:textColor="#000000"
        android:layout_marginTop="350dp"
        android:layout_marginLeft="100dp"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="of"
        android:textSize="20dp"
        android:textColor="#000000"
        android:layout_marginTop="370dp"
        android:layout_marginLeft="170dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Library Management of IST"
        android:textSize="20dp"
        android:textColor="#000000"
        android:layout_marginTop="390dp"
        android:layout_marginLeft="65dp"/>

</RelativeLayout>

2 个答案:

答案 0 :(得分:1)

堆栈跟踪可能会产生误导。您的drawable可能有问题。尝试使用其他@drawable,看看它是否有效。

答案 1 :(得分:0)

android:src="@drawable/ist_logo

在此行中更改您正在使用的图片并使用png格式的另一张较小的图片