Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

android - Error inflating class CollapsingToolbarLayout

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...