Android二进制布局膨胀异常

时间:2017-01-05 12:49:56

标签: java android android-layout android-linearlayout

我的布局

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

8 个答案:

答案 0 :(得分:4)

错误指定为:

原因:android.view.InflateException:二进制XML文件第1行: 二进制XML文件第1行:错误放大类布局,原因是: android.view.InflateException:二进制XML文件第1行:错误 导致类布局夸大的原因:java.lang。 ClassNotFoundException: 在路径上找不到类“ 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.gradle块添加到dataBinding文件中,以便在我们的应用程序中使用它们。

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

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

请参阅Data binding library

答案 1 :(得分:0)

确保已将以下依赖项添加到build.gradle文件中:

compile 'de.hdodenhof:circleimageview:2.1.0'

答案 2 :(得分:0)

xml名称空间必须是:

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"

因此,将您的线性布局编辑为:

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

另外,请确保您已将此gradle依赖项添加到应用程序的模块中:

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

答案 3 :(得分:0)

这个问题肯定与无效的xml有关。
为了进行故障排除,请确保可以找到xml文件中的所有元素。
您可以通过ctrl(或cmd)进行验证-单击所有布局项目。 例如,当您不为compat元素使用正确的名称空间时,就会出现问题。

答案 4 :(得分:0)

当我添加build.gradle时,它对我有用,因此您可以尝试。

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

答案 5 :(得分:0)

我相信没有任何特定原因导致此问题。 我尝试实施上面发布的所有解决方案。

对我来说,问题是我包含布局的方式

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

基本上,我将feed_fail_layout中包含的所有内容都带到主布局中。

答案 6 :(得分:0)

此异常的原因是因为您试图使用未膨胀的视图。

在使用 Navigation 的情况下,碰巧我试图导航到一个视图,该视图在任何时候都不会膨胀(无论是否与DI)。因此,请确保您没有在nav_graph

中的活动中执行不允许的操作

GL

答案 7 :(得分:0)

这是因为系统试图找到正确的根布局元素,并且它获取 layout 元素作为根元素,并在您没有​​使用任何绑定库时抛出错误

解决方案
在您的内容视图 xml 文件中,交叉检查您的根布局是否正确。如果将其设置为 layout,则将其替换为 LinearLayoutRelativeLayoutFrameLayout 或任何您方便使用的内容。
同时确保您的 {{1 }} 方法设置正确。

如果您使用绑定库,请在您的应用级 setContentView 文件中使用以下方法。

build.gradle