Error inflating class CollapsingToolbarLayout

error inflating class android support design widget bottomnavigationview androidx
collapsing toolbar'' android
layout inside collapsingtoolbarlayout
collapsingtoolbarlayout androidx
error inflating class android support design .widget appbarlayout
collapsing toolbar documentation
android collapsing toolbar with image
error inflating class com google android material tabs tablayout

My CollapsingToolbarLayout crashes because of Error inflating class android.support.design.widget.CollapsingToolbarLayout.

I updated the android studio last weekend. Before the updated, it works fine. After I updated it, it crashed. However, I tried to downgrade it to 2.0.0 version and it's not working anymore. My coworker has no problem with the CollapsingToolbarLayout. I am not sure what happened.

The error was:

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)

Here's my CollapsingToolbarLayout:

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

Here's my gradle file:

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'

Do you guys have any idea? Thanks.

I found a solution May it work try it:

add below code in gradle build file

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

Seems like it is having version conflict issue. All support library must be of same version. However, I didn't use v4 support library before and it works. I don't know why updatimg android studio to 2.1.1 causes the issue. I just force all v4 library to the same as other support libraries.

Error inflating class android.support.design.widget , i am getting Error inflating class android.support.design.widget. CollapsingToolbarLayout full error log is given. I need to use the version 23.2 or� Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

I know there is an accepted answer already, BUT it is not working (or no longer working).

I spent a couple of hours researching on this error, what I came up was this.

First, due to initial release of Android Nougat also known as Android 7.0 (API 24) compileSdkVersion 24 is now available. To do that, you have to update your sdk. Step 1

Second, is to update your gradle files (internet connection required). Step 2

Also Update this part of app.gradle

Third (optional) Clean Project, Build Project (Both under Build Tab)

I hope this helped someone out there and save some few hours of researching.

Cheers / Happy coding

error inflating class android.support.design.widget , error inflating class android.support.design.widget.collapsingtoolbarlayout #212. Open. Y-JH opened this issue on Sep 12, 2017 � 1 comment. Open� I had the same issue, @Shumin's code is effective too but it is better to remove conflicts instead of bypassing them. To find the conflict - In Android Studio, open Terminal and enter gradlew app:dependencies.

i found two solutions,

first one is

app:statusBarScrim="@null"

second is to force app

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

Sources taken from here

Error inflating class android.support.design.widget , android.view.InflateExceptionBinary XML file line #138: Error inflating class android.support.design.widget.CollapsingToolbarLayout. This crash was crawled � Adding further to @NileshRathod's answer, errors regarding inflating classes occur almost only due to incorrect dependencies in the app level build.gradle file. You must add the following dependency in you app level build.gradle file:

I had the same issue, @Shumin's code is effective too but it is better to remove conflicts instead of bypassing them. To find the conflict -

  1. In Android Studio, open Terminal and enter gradlew app:dependencies.

  2. Check the dependencies tree and see which library is causing conflict

Update:- To check for conflicts, check the dependencies of each library and see if you aren't using the same dependency in some other library but with different version. For example, in the image below, com.android.support:appcompat-v7 is dependent on com.android.support:support-vector-drawable:23.4.0. If you find some other library depending on com.android.support:support-vector-drawable but the version is different, then you have found your conflict.

Error inflating class CollapsingToolbarLayout, My CollapsingToolbarLayout crashes because of Error inflating class android. support.design.widget.CollapsingToolbarLayout. CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout . CollapsingToolbarLayout contains the following features:

My issue was that not all of the support library gradle imports we the same, eg, I had:

  compile('com.android.support:recyclerview-v7:23.4.0') {
        exclude module: 'support-v4'
    }
  compile 'com.android.support:support-annotations:24.0.0'

changing it so all imports were 24.0.0 enabled the application to run without issues.

Android Error inflating class android.support.design.widget , In my application I want to use this support widgets but I get error: Error inflating class android.support.design.widget.CollapsingToolbarLayout After much more� I am developing an app which have Tab with swipe functionality. I am using Eclipse to develop. I have imported the support design library as Library through Property. During run, i am keep getting

android - Inflate Exception avec FloatingActionButton, MainActivity}: android.view.InflateException: Binary XML file line #45: Error inflating class android.support.design.widget.FloatingActionButton at android.app . Only on Samsung Galaxy Note Edge(Android 5.0.1), I am getting android.view.InflateException: Binary XML file line #23: Error inflating class android.support.design

膨胀类android.support.design.widget.CollapsingToolbarLayout时 , CollapsingToolbarLayout时出错. Binary XML file line #18: Error inflating class android.support.design.widget.CollapsingToolbarLayout [closed]. CollapsingToolBarLayout-status bar scrim color doesn't change CollapsingToolbarLayout and hide toolbar while scrolling Transparent AppBarLayout and CollapsingToolbarLayout

Error Inflating CollapsingToolbarLayout, line #31: Binary XML file line #31: Error inflating class android.support.design. widget.CollapsingToolbarLayout at android.app.ActivityThread. He encontrado una solución Que funcione probarlo: Agregue debajo del código en el archivo de compilación de gradle . compile ('com.android.support:support-v4:23.4.0'){ force = true; }

Comments
  • I think there is more to that error message than you are showing.
  • Hi @cricket_007, you are correct. there's more error message and it's all about error AppCompatActivity.setContentView. Do you have any idea? Thanks
  • Look for the words "Caused by". You are getting a "NoSuchMethodError", which would mean that the different versions of the support library seem to have added some additional methods
  • work for me too after adding firebase and update play services
  • Just update all dependencies to 'v7:24.1.1' and change compileSdkVersion to 24, targetSdkVersion to 24 then Rebuild project. Thats all
  • @KennyDabiri That's not a real solution, you are changing your target and compile SDK. Are you sure you have implemented all the new changes in Nougat ? If not, your app will start crashing due to API 24 changes.
  • This is more of a hack then a solution
  • This is the better solution!
  • Glad it helps. Cheers
  • How are you able to detect the conflicting dependency from that view, i can't see any sign that shows the differences.
  • @KennyDabiri Check which library is dependent on which library versions, there you will find the conflict. It's not very clear in the image but that is how you do it.
  • @KennyDabiri Updated answer, tell me if it doesn't help.
  • Okay would look into it