Android 二进制布局膨胀异常: ClassNotFoundException: 在 path 上找不到类 “android.view.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>

例外

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

答案 1

当我添加它时,它对我有用,所以你可以尝试。build.gradle

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

答案 2

错误指定为:

原因: android.view.inflateException: Binary XML 文件行 #1: 二进制 XML 文件行 #1: 错误膨胀类布局 由: android.view.InflateException: 二进制 XML 文件行 #1: 错误膨胀类布局 由: java.lang 引起。ClassNotFoundException:在 path 上找不到类 “android.view.layout”:

在应用程序中实现数据绑定时,会导致此错误。在这种情况下,用户正在使用数据绑定(请参阅指定的值内部):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}" />
                         ...

因此,我们需要将块添加到我们的文件中,以便在我们的应用程序中使用它们。/app/build.gradledataBinding

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

解决此问题的另一种方法是找到包含的布局并删除标记,因为项目中未启用 dataBinding。

请参见数据绑定库


推荐