文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

【Android运行时错误】Error inflating class CollapsingToolbarLayout

2023-08-20 05:49

关注

近期在调试代码时,突然遇到这样的一个错误,Error inflating class CollapsingToolbarLayout,这里记录一下。

刚开始并不知道问题所在,以为是自己的代码出问题了,因为毕竟报的错误是代码中的

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.itbird.test/com.itbird.test.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.itbird.test.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.itbird.test.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.itbird.test-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.itbird.test.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)

自然而然,我就去查找自己的xml文件,到底有什么错误了

        <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"            >         //...省略        </android.support.design.widget.CollapsingToolbarLayout>

看着xml代码很正常,那么我们还是返回问题本身,错误日志里面是说CollapsingToolbarLayout控件解析异常,那么是否是android.support包导入有问题?
最终,尝试在 gradle文件中,添加v4的支持,运行正常了。

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

来源地址:https://blog.csdn.net/baobei0921/article/details/128967290

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯