MaxExplode
MaxExplode

Reputation: 2007

Android binary layout inflate exception : ClassNotFoundException: Didn't find class "android.view.layout" on path:

My layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        card_view:cardCornerRadius="4dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <FrameLayout
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/profilePic"
                    android:layout_width="96dp"
                    android:layout_height="96dp"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/avatar" />

            </FrameLayout>

            <RelativeLayout
                android:id="@+id/user_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/header">

                <ImageView
                    android:id="@+id/divider"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:src="@color/contentDividerLine" />

                <TextView
                    android:id="@+id/username"
                    style="@style/Base.Widget.AppCompat.Button.Borderless"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="bottom"
                    android:drawablePadding="5dp"
                    android:padding="8dp"
                    android:text="Name"
                    android:textColor="@color/Black" />


            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/user_view">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:src="@color/contentDividerLine" />

                <TextView
                    android:id="@+id/email"
                    style="@style/Base.Widget.AppCompat.Button.Borderless"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="bottom"
                    android:drawablePadding="5dp"
                    android:padding="8dp"
                    android:text="Email"
                    android:textColor="@color/Black" />


            </RelativeLayout>
        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        card_view:cardCornerRadius="4dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RelativeLayout
                android:id="@+id/settings_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/settings_title"
                    style="@style/Base.Widget.AppCompat.Button.Borderless"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="bottom"
                    android:drawablePadding="5dp"
                    android:padding="8dp"
                    android:text="Settings"
                    android:textColor="@color/Black" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_below="@id/settings_title"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:src="@color/contentDividerLine" />


            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/settings_header">

                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical">

                        <include
                            layout="@layout/notification_pref"
                            app:label="@{@string/show_bounds}" />

                        <include
                            layout="@layout/location_pref"
                            app:label="@{@string/show_offsets}" />

                        <include
                            layout="@layout/sync_pref"
                            app:label="@{@string/show_bounds}" />

                        <include
                            layout="@layout/analytics_pref"
                            app:label="@{@string/show_offsets}" />

                    </LinearLayout>

                </ScrollView>
            </RelativeLayout>
        </RelativeLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

Exception

01-05 18:17:15.102 10834-10834/com.creativemoments.unipoint E/CustomActivityOnCrash: 
    App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler
                                                                                 

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.creativemoments.unipoint/com.creativemoments.unipoint.profile.ProfileActivity}:
    android.view.InflateException: Binary XML file line #2: Error inflating class layout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5233)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class layout
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.creativemoments.unipoint.profile.ProfileActivity.onCreate(ProfileActivity.java:28)
at android.app.Activity.performCreate(Activity.java:6001)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368) 
at android.app.ActivityThread.access$800(ActivityThread.java:144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5233) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.layout" on path: DexPathList[[zip file "/data/app/com.creativemoments.unipoint-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:665)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:65)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:892) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
at com.creativemoments.unipoint.profile.ProfileActivity.onCreate(ProfileActivity.java:28) 
at android.app.Activity.performCreate(Activity.java:6001) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368) 
at android.app.ActivityThread.access$800(ActivityThread.java:144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5233) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) 
Suppressed: java.lang.ClassNotFoundException: android.view.layout
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 32 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Upvotes: 18

Views: 12330

Answers (8)

Ankur Jagani
Ankur Jagani

Reputation: 9

It's because system tries to find the proper root layout element and it gets the layout element as a root and throws the error if you are not using any binding library.

Solution
In your content view xml file, cross check that you have correct root layout. If it is set as a layout then replace it with LinearLayout, RelativeLayout or FrameLayout or anything you are convenient with.
Also make sure your setContentView method setup correctly.

If you are using binding library, use below method in your app level build.gradle file.

android {
    //...
     dataBinding {
            enabled = true 
     }
}

Upvotes: 0

Jorgesys
Jorgesys

Reputation: 126563

The error is specified as:

Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class layout Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class layout Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.layout" on path:

This error is caused when you have implemented data binding in your application. In this case the user is using data binding (see inside the specified value of app:label=):

                        ...
                        <include
                            layout="@layout/notification_pref"
                            app:label="@{@string/show_bounds}" />

                        <include
                            layout="@layout/location_pref"
                            app:label="@{@string/show_offsets}" />

                        <include
                            layout="@layout/sync_pref"
                            app:label="@{@string/show_bounds}" />

                        <include
                            layout="@layout/analytics_pref"
                            app:label="@{@string/show_offsets}" />
                         ...

So we need to add into our /app/build.gradle file the block dataBinding, to enable their use in our application.

android {
    ...
    ...
    ...
    dataBinding {
        enabled = true
    }
}

Another way to resolve this is by locating the layout that was included and removing the tag since dataBinding is not enabled in the project.

see Data binding library

Upvotes: 9

Braian Coronel
Braian Coronel

Reputation: 22905

The cause of this exception is because you are trying to use a view that was not inflated.

In the case of using Navigation, it happened to me that I was trying to navigate to the destination of a view that at no time was inflated (whether or not with DI) within the activity. Therefore, make sure that you do not have actions not allowed inside the activity in the nav_graph

GL

Upvotes: 0

Arpit
Arpit

Reputation: 1289

I believe there is no one particular cause of this problem. I tried implementing all the solution posted above.

For me the problem is the way i included layout

<include layout="@layout/feed_fail_layout" />

Basically I bring everything included in feed_fail_layout to the main layout.

Upvotes: 0

codeocity
codeocity

Reputation: 477

When I added in build.gradle it worked for me so you can try.

android {
    //...
     dataBinding {
            enabled = true 
     }
}

Upvotes: 34

Trace
Trace

Reputation: 18899

This problem definitely has something to do with invalid xml.
In order to troubleshoot, make sure that all elements in the xml file can be found.
You can verify this by ctrl (or cmd) - clicking all layout items. Issues can arise when you for example don't use the correct namespace for compat elements.

Upvotes: 1

sats
sats

Reputation: 657

the xml namespace must be:

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

So, edit your linear layout as:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">

....

</LinearLayout>

Also, make sure that you hav added this gradle dependency to your app's module:

compile 'com.android.support:cardview-v7:21.0.+'

Upvotes: 0

Ashwini.patil
Ashwini.patil

Reputation: 102

Make sure you have added the following dependency to your build.gradle file:

compile 'de.hdodenhof:circleimageview:2.1.0'

Upvotes: 0

Related Questions