0

I'm getting below error in my xml file of android project.

android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ImageView

I've seen the this solution but can't understand/ it doesn't in my project. Is there any problem with the xml file? Or do I need to work on activity file?

I'm getting the error while adding a custom navigation drawer.

Here is the error

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) 

Here is my activity file:

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

Here is my xml file of splash screen

<?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
  • Are you sure that there is nothing more in the stack trace, below what you have posted? Commented Sep 13, 2017 at 22:51
  • there are some other issues. But for simplicity I posted this Commented Sep 14, 2017 at 1:37

2 Answers 2

1

Stack trace may be misleading. There might be a problem with your drawable. Try a different @drawable and see if it works.

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

1 Comment

thank you. that problem is solved, but now in next activity I got this error: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
0
android:src="@drawable/ist_logo

in this line change the picture you're using and use another smaller picture in png format

Comments

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.