NoSuchFieldError:没有静态字段BottomNavigationView_menu

问题描述 投票:0回答:1

我遇到一个错误,在我的项目中我试图在主屏幕上添加 BottomNavigationBar,

所以我有以下代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/main_activity"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:menu="@menu/bottom_navigation_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>

在这里你可以在我的 res/menu 上找到我的 Bottom_navigation_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/navigation_home"
        android:icon="@drawable/ic_home"
        android:title="Home" />

    <item
        android:id="@+id/navigation_dashboard"
        android:icon="@drawable/ic_dashboard"
        android:title="Dashboard" />

    <item
        android:id="@+id/navigation_notifications"
        android:icon="@drawable/ic_notification"
        android:title="Notifications" />
</menu>

问题是当应用程序打开时,在我的主屏幕上我发生崩溃并出现以下错误:

java.lang.NoSuchFieldError: No static field BottomNavigationView_menu of type I in class Lcom/google/android/material/R$styleable; or its superclasses

你知道为什么吗?

android bottomnavigationview
1个回答
0
投票

您提到的错误有多种原因。
最常见的情况之一是您有多个同名文件,包括库。
为什么不将

bottom_navigation_menu.xml
重命名为其他名称?

© www.soinside.com 2019 - 2024. All rights reserved.