android.view.InflateException: Binary XML file line #0: Error inflating class <unk

本文记录了一次在使用ConstraintLayout时遇到的错误及其解决过程。问题源于Fragment布局文件中不正确的背景设置,移除该设置后问题得到解决。此外,还提到了因资源文件存放位置不当引发的类似问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

fragment里面用了constraintlayout

结果一个劲报错~~

我的天啊~~

11-29 17:30:12.053 19479-19479/com.youhui2000.dabaifanyi E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: com.youhui2000.dabaifanyi, PID: 19479
                                                                           android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
                                                                               at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                               at com.youhui2000.dabaifanyi.ui.base.BaseFragment.onCreateView(BaseFragment.java:31)

 

最后发现 原来是不该设置这个背景~

错误xml

 

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_launcher_background">


    <TextView
        android:id="@+id/textView"
        android:layout_width="261dp"
        android:layout_height="272dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text="main_fragment"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

 

 

 

将background取消 果断正常了·~

新手伤不起

 

总结:资源文件引用错误因为后面还是遇到了同样的问题~~ 结果是某个drawable放到drawable-v24里面去了,放回drawable就好了

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值