Android Studio 错误膨胀类com.谷歌.android.材料.浮动操作按钮.浮动操作按钮

lmvvr0a8  于 2022-12-19  发布在  Android
关注(0)|答案(1)|浏览(118)

当我在手机上运行我的应用程序时,我收到一个“膨胀类com.google.android.material.floatingactionbutton. floatingactionbutton错误”。我知道还有其他帖子,但它不一样,至少那里的答案对我不起作用。
因此,当我运行我的应用程序上的emlulator一切工作正常。没有错误的或任何东西。当我运行相同的应用程序在我的手机上(与相同的android API版本),我得到下面的错误。

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tripmemory, PID: 25604
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tripmemory/com.tripmemory.TripActivity}: android.view.InflateException: Binary XML file line #21 in com.tripmemory:layout/activity_trip: Binary XML file line #21 in com.tripmemory:layout/activity_trip: Error inflating class com.google.android.material.floatingactionbutton.FloatingActionButton
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4166)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4312)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
    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:2571)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8741)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
 Caused by: android.view.InflateException: Binary XML file line #21 in com.tripmemory:layout/activity_trip: Binary XML file line #21 in com.tripmemory:layout/activity_trip: Error inflating class com.google.android.material.floatingactionbutton.FloatingActionButton
 Caused by: android.view.InflateException: Binary XML file line #21 in com.tripmemory:layout/activity_trip: Error inflating class com.google.android.material.floatingactionbutton.FloatingActionButton
 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:876)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1028)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:983)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1145)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1106)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:692)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:544)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:491)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:710)
    at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
    at com.tripmemory.TripActivity.onCreate(TripActivity.java:44)
    at android.app.Activity.performCreate(Activity.java:8578)
    at android.app.Activity.performCreate(Activity.java:8557)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4147)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4312)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
    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:2571)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8741)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) 
E/AndroidRuntime: Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 77: TypedValue{t=0x2/d=0x7f0300e0 a=-1}, theme={InheritanceMap=[id=0x7f11024dcom.tripmemory:style/Theme.TripMemory, id=0x7f110225com.tripmemory:style/Theme.MaterialComponents.DayNight.DarkActionBar, id=0x7f11021ecom.tripmemory:style/Theme.MaterialComponents, id=0x7f11005acom.tripmemory:style/Base.Theme.MaterialComponents, id=0x7f110096com.tripmemory:style/Base.V21.Theme.MaterialComponents, id=0x7f110083com.tripmemory:style/Base.V14.Theme.MaterialComponents, id=0x7f110084com.tripmemory:style/Base.V14.Theme.MaterialComponents.Bridge, id=0x7f110126com.tripmemory:style/Platform.MaterialComponents, id=0x7f1101eacom.tripmemory:style/Theme.AppCompat, id=0x7f110046com.tripmemory:style/Base.Theme.AppCompat, id=0x7f1100a8com.tripmemory:style/Base.V28.Theme.AppCompat, id=0x7f1100a5com.tripmemory:style/Base.V26.Theme.AppCompat, id=0x7f11009fcom.tripmemory:style/Base.V23.Theme.AppCompat, id=0x7f11009dcom.tripmemory:style/Base.V22.Theme.AppCompat, id=0x7f110092com.tripmemory:style/Base.V21.Theme.AppCompat, id=0x7f1100aacom.tripmemory:style/Base.V7.Theme.AppCompat, id=0x7f110124com.tripmemory:style/Platform.AppCompat, id=0x7f11012fcom.tripmemory:style/Platform.V25.AppCompat, id=0x103022eandroid:style/Theme.Material.NoActionBar, id=0x1030224android:style/Theme.Material, id=0x1030005android:style/Theme], Themes=[com.tripmemory:style/Theme.TripMemory, forced, com.tripmemory:style/Theme.AppCompat.Empty, forced, android:style/Theme.DeviceDefault.Light.DarkActionBar, forced]}
    at android.content.res.TypedArray.getColorStateList(TypedArray.java:600)
    at android.view.View.<init>(View.java:6211)
    at android.widget.ImageView.<init>(ImageView.java:196)
    at android.widget.ImageButton.<init>(ImageButton.java:96)
    at android.widget.ImageButton.<init>(ImageButton.java:92)
    at com.google.android.material.internal.VisibilityAwareImageButton.<init>(VisibilityAwareImageButton.java:47)
    at com.google.android.material.floatingactionbutton.FloatingActionButton.<init>(FloatingActionButton.java:207)
    at com.google.android.material.floatingactionbutton.FloatingActionButton.<init>(FloatingActionButton.java:201)
        ... 29 more

在其他帖子中,我读到主题是错误的,他们建议将其更改为materialComponents的子,但对我来说已经是这样了:

Theme.MaterialComponents.DayNight.DarkActionBar

我读到有人改变背景,但我没有这样做:

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/floatingActionButton"
    app:srcCompat="@drawable/plus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/margin_M"
    android:backgroundTint="?attr/colorAccent1"
    android:clickable="true"/>

简而言之,我不知道根本原因,特别是因为它在模拟器中工作正常。有人能帮我吗?

qybjjes1

qybjjes11#

如果您在堆栈跟踪中向下查看,您将看到这一行:
E/安卓运行时:原因:java. lang.不支持的操作异常:无法解析索引77处的属性:类型值{t = 0x2/d = 0x7f0300e0 a = -1} ...
存在无法解析的属性。ID为"0x7f0300e01",由于错误指向浮动操作按钮,因此将在此处引用缺少的属性。
这看起来像一个主题问题。我会看看

android:layout_margin="@dimen/margin_M"
android:backgroundTint="?attr/colorAccent1"

并逐一删除每个值,以隔离问题并从那里着手。(这只是为了隔离问题。我并不是说您不需要这些值。)

    • 更新:**实际上,因为跟踪中出现了以下行

在android.内容. res.类型数组. getColorStateList(类型数组. java:600)
我认为问题出在?attr/colorAccent1上。检查你的主题是否存在这个属性。同时,确保这个属性被定义为一个颜色。

相关问题