当前位置: 首页 > 知识库问答 >
问题:

inflating类CollapsingToolbarLayout时出错

满昊然
2023-03-14
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.android/com.test.android.ui.activity.RandomActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.CollapsingToolbarLayout
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:135)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                      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:903)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                   Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.CollapsingToolbarLayout
                                                                      at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                                                                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
                                                                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                                                                      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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
                                                                      at com.test.android.ui.activity.RefreshableActivity.onCreate(RefreshableActivity.java:31)
                                                                      at android.app.Activity.performCreate(Activity.java:5990)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:135) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                      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:903) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
                                                                   Caused by: java.lang.reflect.InvocationTargetException
                                                                      at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                      at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
                                                                      at android.view.LayoutInflater.createView(LayoutInflater.java:607)
                                                                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
                                                                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
                                                                      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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136) 
                                                                      at com.test.android.ui.activity.RefreshableActivity.onCreate(RefreshableActivity.java:31) 
                                                                      at android.app.Activity.performCreate(Activity.java:5990) 
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:135) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                      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:903) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
                                                                   Caused by: java.lang.NoSuchMethodError: No static method setLayoutDirection(Landroid/graphics/drawable/Drawable;I)V in class Landroid/support/v4/graphics/drawable/DrawableCompat; or its super classes (declaration of 'android.support.v4.graphics.drawable.DrawableCompat' appears in /data/app/com.test.android-1/base.apk)
                                                                      at android.support.design.widget.CollapsingToolbarLayout.setStatusBarScrim(CollapsingToolbarLayout.java:663)
                                                                      at android.support.design.widget.CollapsingToolbarLayout.<init>(CollapsingToolbarLayout.java:197)
                                                                      at android.support.design.widget.CollapsingToolbarLayout.<init>(CollapsingToolbarLayout.java:132)
                                                                      at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                      at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
                                                                      at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
                                                                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
                                                                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
                                                                      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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136) 
                                                                      at com.test.android.ui.activity.RefreshableActivity.onCreate(RefreshableActivity.java:31) 
                                                                      at android.app.Activity.performCreate(Activity.java:5990) 
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                      at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:135) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                      at java.lang.reflect.Method.invoke(Method.java:372)
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true"
            app:contentScrim="@color/blue"
            app:statusBarScrim="@color/blue_dark"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            >

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                />

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <include
        layout="@layout/layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

</android.support.design.widget.CoordinatorLayout>
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:support-v13:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:customtabs:23.4.0'
compile 'com.android.support:design:23.4.0'

共有1个答案

凌嘉勋
2023-03-14

我找到了一个可行的解决办法试试看:

在gradle构建文件中添加以下代码

compile ('com.android.support:support-v4:23.4.0'){
    force = true;
}

似乎有版本冲突的问题。所有的支持库必须是相同的版本。但是,我以前没有使用过v4支持库,它起作用了。我不知道为什么将android studio更新到2.1.1会导致这个问题。我只是强制所有v4库与其他支持库相同。

 类似资料: