按钮'info.hoang8f:fbutton:1.0.5'有一些问题



大家好,有人可以查看我在运行应用程序后遇到的此错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.foodapp, PID: 9804
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.foodapp/com.example.foodapp.MainActivity}: android.view.InflateException: Binary XML file line #48 in com.example.foodapp:layout/activity_main: Binary XML file line #48 in com.example.foodapp:layout/activity_main: Error inflating class info.hoang8f.widget.FButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3356)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3500)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
Caused by: android.view.InflateException: Binary XML file line #48 in com.example.foodapp:layout/activity_main: Binary XML file line #48 in com.example.foodapp:layout/activity_main: Error inflating class info.hoang8f.widget.FButton
Caused by: android.view.InflateException: Binary XML file line #48 in com.example.foodapp:layout/activity_main: Error inflating class info.hoang8f.widget.FButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.foodapp.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Activity.performCreate(Activity.java:7973)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3329)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3500)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
E/AndroidRuntime:     at android.content.res.TypedArray.getColor(TypedArray.java:533)
at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
at info.hoang8f.widget.FButton.<init>(FButton.java:52)
... 30 more

这是主要活动代码:

<LinearLayout
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/logo_eat_it" />
<TextView
android:gravity="center"
android:id="@+id/txtSlogan"
android:text="@string/slogan"
android:textColor="@android:color/white"
android:textSize="17dp"
android:layout_width="200dp"
android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<info.hoang8f.widget.FButton
android:id="@+id/btnSignUp"
android:text="Sign Up"
android:textColor="@android:color/white"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_margin="8dp"
app:buttonColor="@color/btnSignUp"
app:shadowColor="@android:color/black"
app:shadowEnabled="true"
app:shadowHeight="5dp"
app:cornerRadius="4dp"
android:layout_height="wrap_content"  />
<info.hoang8f.widget.FButton
android:id="@+id/btnSignIn"
android:text="Sign In"
android:textColor="@android:color/white"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_margin="8dp"
app:buttonColor="@color/btnSignActive"
app:shadowColor="@android:color/black"
app:shadowEnabled="true"
app:shadowHeight="5dp"
app:cornerRadius="4dp"
android:layout_height="wrap_content"  />
</LinearLayout>   

Binary XML file line #48 in com.example.foodapp:layout/activity_main:Error inflating class info.hoang8f.widget.FButton

您的布局似乎无法识别 [FButton][1]

因此,请确保将以下依赖项添加到build.gradle模块文件中

implementation 'info.hoang8f:fbutton:1.0.5'

更新:将布局包装到单个根视图组中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/logo_eat_it" />
<TextView
android:id="@+id/txtSlogan"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/slogan"
android:textColor="@android:color/white"
android:textSize="17dp" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="2">
<info.hoang8f.widget.FButton
android:id="@+id/btnSignUp"
app:buttonColor="@color/btnSignUp"
app:cornerRadius="4dp"
app:shadowColor="@android:color/black"
app:shadowEnabled="true"
app:shadowHeight="5dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:text="Sign Up"
android:textColor="@android:color/white" />
<info.hoang8f.widget.FButton
android:id="@+id/btnSignIn"
app:buttonColor="@color/btnSignActive"
app:cornerRadius="4dp"
app:shadowColor="@android:color/black"
app:shadowEnabled="true"
app:shadowHeight="5dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:text="Sign In"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
[1]: https://github.com/hoang8f/android-flat-button

最新更新