web-dev-qa-db-fra.com

Ligne de fichier XML binaire n ° 0: erreur lors du gonflage de la classe <inconnu>

J'ai une erreur lors de l'exécution d'un jeu de quiz. Quelque chose comme ça (quand la gaméactivité est ouverte). Mon application s’arrête et je rencontre une erreur de fichier XML binaire sur la ligne 0. C'est un peu bizarre, parce que je n'ai pas vu ce problème avec la ligne 0, alors j'ai besoin de votre aide, tout le monde. Merci!

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) 

Où MainGameActivity.Java:36 est: setContentView(R.layout.activity_game_main);

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>

Où est le problème?

7
Vhailors V

Le problème vient de la bibliothèque elle-même. Si vous vérifiez attrs.xml :

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

Comme vous pouvez le constater, la variable buttonColor accepte uniquement la valeur de couleur, la référence de couleur NOT, et la vue tente de convertir la valeur de référence que vous transmettez en xml en couleur et génère une exception. Vous ne pouvez donc utiliser que la couleur pour cette couleur. attribut (comme ceci: # 000000) Ou branchez le projet et modifiez attrs.xml comme ceci:

<attr name="buttonColor" format="color|reference" />
8
ҒάгՏҺαԃ ッ

Essayez de supprimer la propriété cornerRadius, car le problème peut provenir de la bibliothèque.

fbutton:cornerRadius="10dp"

Enlevez tous les boutons et ça marche bien

0
Munir