23

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.

3
  • I think there is more to that error message than you are showing. May 24, 2016 at 20:44
  • 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
    – Shumin
    May 24, 2016 at 21:28
  • 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 May 25, 2016 at 0:12

10 Answers 10

39

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.

4
  • 1
    work for me too after adding firebase and update play services
    – androidXP
    Sep 26, 2016 at 8:34
  • Just update all dependencies to 'v7:24.1.1' and change compileSdkVersion to 24, targetSdkVersion to 24 then Rebuild project. Thats all Sep 27, 2016 at 23:24
  • 1
    @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. Sep 28, 2016 at 8:59
  • This is more of a hack then a solution Oct 6, 2016 at 5:58
17

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

enter image description here

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

enter image description here

Also Update this part of app.gradle

enter image description here

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

2
  • 1
    This is the better solution! Oct 6, 2016 at 5:58
  • Glad it helps. Cheers
    – ralphgabb
    Oct 7, 2016 at 1:15
3

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

1

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.Terminal Image

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

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.

4
  • How are you able to detect the conflicting dependency from that view, i can't see any sign that shows the differences. Sep 27, 2016 at 22:55
  • @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. Sep 28, 2016 at 8:51
  • @KennyDabiri Updated answer, tell me if it doesn't help. Sep 28, 2016 at 8:57
  • Okay would look into it Sep 28, 2016 at 11:00
0

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.

0

Hello Friend i face this issue

Just Make

compileSdkVersion 25
buildToolsVersion "25.0.2"

And All support gradle change to 25.1.1 it's work for me .

0

please add below code in menifiest.xml.

 <activity android:name=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

and style resource file

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
0

I had the same issue showing the same error while inflating the CollapsingToolbar.. I had the following dependencies in my app gradle file

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.google.firebase:firebase-ads:10.0.1'

and build tool 25.0.2 with compiled with API 23 sdk. I than checked the dependencies and found that firebase uses

android:support:support-v4:24.0.0

and the appcompat uses

android:support:support-v4-23.4.0 -> 24.0

Hence, I changed all the build library number to

compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.google.firebase:firebase-ads:10.0.1'

It worked for me now. How durable ? I don't have any idea.

0

This worked for me. Change you your appcompact and design libray version as follows,

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
0

If you are working on Oreo or upper sdk and using a drawable in CollapsingToolbar, check this drawable exists in normal drawable folder and drawable-v24 folder.

If your drawable is only in drawable-v24 folder and running the app under Oreo sdk, Android Studio logcat says "crash in CollapsingToolbar" but real problem is missing some drawables in your drawable folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.