Java 二进制XML文件第0行:膨胀class info.hoang8f.widget.FButton时出错

Java 二进制XML文件第0行:膨胀class info.hoang8f.widget.FButton时出错,java,android,android-studio,Java,Android,Android Studio,我正在尝试使用Android Studio创建一个应用程序,然后我面临这个问题,我的应用程序总是停止 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.alfin.senior_routine, PID: 20663 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alfin.senior_routine/c

我正在尝试使用Android Studio创建一个应用程序,然后我面临这个问题,我的应用程序总是停止

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.alfin.senior_routine, PID: 20663
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alfin.senior_routine/com.example.alfin.senior_routine.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
      at android.app.ActivityThread.-wrap11(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
   Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
      at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
      at com.example.alfin.senior_routine.MainActivity.onCreate(MainActivity.java:16)
      at android.app.Activity.performCreate(Activity.java:6237)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
   Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
      at android.view.LayoutInflater.createView(LayoutInflater.java:645)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
      at com.example.alfin.senior_routine.MainActivity.onCreate(MainActivity.java:16) 
      at android.app.Activity.performCreate(Activity.java:6237) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
   Caused by: java.lang.reflect.InvocationTargetException
      at java.lang.reflect.Constructor.newInstance(Native Method)
      at android.view.LayoutInflater.createView(LayoutInflater.java:619)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
      at com.example.alfin.senior_routine.MainActivity.onCreate(MainActivity.java:16) 
      at android.app.Activity.performCreate(Activity.java:6237) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
   Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x5
      at android.content.res.TypedArray.getColor(TypedArray.java:451)
      at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
      at info.hoang8f.widget.FButton.<init>(FButton.java:52)
      at java.lang.reflect.Constructor.newInstance(Native Method) 
      at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
      at com.example.alfin.senior_routine.MainActivity.onCreate(MainActivity.java:16) 
      at android.app.Activity.performCreate(Activity.java:6237) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
班级活动:

package com.example.alfin.senior_routine;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button btnExercises,btnSetting,btnCalendar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnExercises = (Button)findViewById(R.id.btnExercise);
        btnExercises.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                Intent intent = new Intent(MainActivity.this,ListExercises.class);
            startActivity(intent);
        }
    });
}
}

课堂活动

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/back"
    tools:context="com.example.alfin.senior_routine.MainActivity">

<ImageView
    android:id="@+id/btnTraining"
    android:layout_centerInParent="true"
    android:src="@drawable/play"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_alignParentBottom="true"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_weight="2"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <info.hoang8f.widget.FButton
            android:id="@+id/btnExercise"
            android:text="Exercises"
            android:textColor="@android:color/white"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="4dp"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            fbutton:buttonColor="@color/colorPrimary"
            fbutton:shadowColor="@color/colorPrimaryDark"
            fbutton:shadowEnabled="true"
            fbutton:shadowHeight="2dp"
            fbutton:cornerRadius="2dp"
            />

        <info.hoang8f.widget.FButton
            android:id="@+id/btnSetting"
            android:text="Setting"
            android:textColor="@android:color/white"
            android:layout_marginLeft="4dp"
            android:layout_marginRight="8dp"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            fbutton:buttonColor="@color/colorPrimary"
            fbutton:shadowColor="@color/colorPrimaryDark"
            fbutton:shadowEnabled="true"
            fbutton:shadowHeight="2dp"
            fbutton:cornerRadius="2dp"
            />

    </LinearLayout>

    <info.hoang8f.widget.FButton
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:id="@+id/btnCalendar"
        android:text="Calendar"
        android:textColor="@android:color/white"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        fbutton:buttonColor="@color/colorPrimary"
        fbutton:shadowColor="@color/colorPrimaryDark"
        fbutton:shadowEnabled="true"
        fbutton:shadowHeight="2dp"
        fbutton:cornerRadius="2dp"
        />

</LinearLayout>
我已经尝试过这个教程,我也在那个链接中复制了代码,但是结果是一样的,请帮助我解决这个问题,谢谢

public class MainActivity extends AppCompatActivity {

    //Button btnExercises,btnSetting,btnCalendar;
    private FButton btnExercises;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnExercises = (FButton)findViewById(R.id.btnExercise);

        btnExercises.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                Intent intent = new Intent(MainActivity.this,ListExercises.class);
            startActivity(intent);
        }
    });
}
}

这是一个库问题,所以不要浪费时间建议更改它,更多信息请参考此

@Alfin H请检查我的ans。非常感谢,我已经解决了此问题,将按钮颜色修改为fButtonColor可以正常工作。这真的很有帮助
public class MainActivity extends AppCompatActivity {

    //Button btnExercises,btnSetting,btnCalendar;
    private FButton btnExercises;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnExercises = (FButton)findViewById(R.id.btnExercise);

        btnExercises.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                Intent intent = new Intent(MainActivity.this,ListExercises.class);
            startActivity(intent);
        }
    });
}
}