java 二进制 XML 文件第 0 行:错误膨胀类 <unknown>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47221195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:32:33  来源:igfitidea点击:

Binary XML file line #0: Error inflating class <unknown>

javaandroidxmllayoutcompiler-errors

提问by Vhailors V

I have error running a quiz game. Something like this (when open gameactivity). My application stop and I ge Binary XML file error on line #0. It`s kinda weird, becouse I didnt see problem like this with line 0, so I need your help, everyone. Thanks!

我在运行问答游戏时出错。像这样的东西(打开游戏活动时)。我的应用程序停止,我在第 0 行出现二进制 XML 文件错误。有点奇怪,因为我没有看到第 0 行有这样的问题,所以我需要大家的帮助。谢谢!

E/AndroidRuntime: FATAL EXCEPTION: main
   Process: sarveshchavan777.triviaquiz, PID: 2901
   java.lang.RuntimeException: Unable to start activity ComponentInfo{sarveshchavan777.triviaquiz/sarveshchavan777.triviaquiz.MainGameActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
       at android.app.ActivityThread.-wrap11(Unknown Source:0)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6540)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
    Caused by: java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Constructor.newInstance0(Native Method)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
       at android.view.LayoutInflater.createView(LayoutInflater.java:650)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:793)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
       at sarveshchavan777.triviaquiz.MainGameActivity.onCreate(MainGameActivity.java:36)
       at android.app.Activity.performCreate(Activity.java:6980)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
       at android.app.ActivityThread.-wrap11(Unknown Source:0)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6540)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
       at android.content.res.TypedArray.getColor(TypedArray.java:473)
       at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
       at info.hoang8f.widget.FButton.<init>(FButton.java:52)
       at java.lang.reflect.Constructor.newInstance0(Native Method) 
       at java.lang.reflect.Constructor.newInstance(Constructor.java:334) 
       at android.view.LayoutInflater.createView(LayoutInflater.java:650) 
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:793) 
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733) 
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) 
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827) 
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:869) 
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) 
       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
       at sarveshchavan777.triviaquiz.MainGameActivity.onCreate(MainGameActivity.java:36) 
       at android.app.Activity.performCreate(Activity.java:6980) 
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) 
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) 
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
       at android.app.ActivityThread.-wrap11(Unknown Source:0) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
       at android.os.Handler.dispatchMessage(Handler.java:105) 
       at android.os.Looper.loop(Looper.java:164) 
       at android.app.ActivityThread.main(ActivityThread.java:6540) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

Where MainGameActivity.java:36 is: setContentView(R.layout.activity_game_main);

其中 MainGameActivity.java:36 是: setContentView(R.layout.activity_game_main);

activity_game_main.xml:

activity_game_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fbutton="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundColor"
    android:orientation="vertical"
    tools:context="sarveshchavan777.triviaquiz.MainGameActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/lightGreen"
        android:minHeight="?actionBarSize">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="0dp">



            <TextView
                android:id="@+id/triviaQuizText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="@string/app_name"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:layout_toLeftOf="@+id/timeText"
                android:layout_toRightOf="@+id/coinText" />

            <TextView
                android:id="@+id/timeText"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:paddingLeft="10dp"
                android:gravity="center"
                android:paddingRight="10dp"
                android:text="@string/time"
                android:textSize="20sp" />

        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

    <View
        android:layout_width="match_parent"
        android:layout_height="10dp"></View>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".5"
        android:background="@color/white"
        android:orientation="vertical">

        <TextView
            android:id="@+id/triviaQuestion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:gravity="center"
            android:text="@string/question"
            android:textColor="@color/grey"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/resultText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text=""
            android:textColor="@color/green"
            android:textSize="30sp" />
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <info.hoang8f.widget.FButton
            android:id="@+id/buttonA"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:onClick="buttonA"
            android:text=""
            android:textColor="@color/grey"
            fbutton:buttonColor="@color/white"
            fbutton:cornerRadius="10dp"
            fbutton:shadowColor="@color/grey" />

        <info.hoang8f.widget.FButton
            android:id="@+id/buttonB"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:onClick="buttonB"
            android:text=""
            android:textColor="@color/grey"
            fbutton:buttonColor="@color/white"
            fbutton:cornerRadius="10dp"
            fbutton:shadowColor="@color/grey" />


        <info.hoang8f.widget.FButton
            android:id="@+id/buttonC"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:onClick="buttonC"
            android:text=""
            android:textColor="@color/grey"
            fbutton:buttonColor="@color/white"
            fbutton:cornerRadius="10dp"
            fbutton:shadowColor="@color/grey" />

        <info.hoang8f.widget.FButton
            android:id="@+id/buttonD"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:onClick="buttonD"
            android:text=""
            android:textColor="@color/grey"
            fbutton:buttonColor="@color/white"
            fbutton:cornerRadius="10dp"
            fbutton:shadowColor="@color/grey" />

    </LinearLayout>


</LinearLayout>

Where is the problem?

哪里有问题?

回答by Farshad Tahmasbi

The problem comes with the library itself, If you check attrs.xml:

问题在于库本身,如果您检查attrs.xml

<attr name="buttonColor" format="color" />

As you can see the buttonColoronly accepts color value, NOTcolor reference, and the view is trying to convert reference value you pass in xml to color and it throws an exception, So you can only use color for this attribute ( like this: #000000) Or fork the project and modify attrs.xmllike this:

正如您所看到的,buttonColor唯一接受颜色值,而不是颜色参考,并且视图正在尝试将您在 xml 中传递的参考值转换为颜色并引发异常,因此您只能为此属性使用颜色(例如:#000000) 或者 fork 项目并attrs.xml像这样修改:

<attr name="buttonColor" format="color|reference" />

回答by Munir

Try to remove cornerRadius property it's causes the problem may be it's library issues

尝试删除cornerRadius 属性它的原因可能是它的库问题

fbutton:cornerRadius="10dp"

Remove it's all buttons and it's work well

删除它的所有按钮,它运行良好