簡體   English   中英

錯誤膨脹類 com.google.android.material.internal.NavigationMenuItemView

[英]Error inflating class com.google.android.material.internal.NavigationMenuItemView

這是我的第一個問題。 如果我忘記發布任何可能有幫助的內容,請告訴我。 我目前正在開展一個項目,將舊 UI 轉換為帶有導航抽屜的 UI。 但是,我不斷收到此錯誤。 我已經花了一段時間試圖弄清楚這一點。 提前感謝任何人在此花費的任何時間!

例外:

android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class com.google.android.material.internal.NavigationMenuItemView
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at com.google.android.material.internal.NavigationMenuPresenter$NormalViewHolder.<init>(NavigationMenuPresenter.java:315)
        at com.google.android.material.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:411)
        at com.google.android.material.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:361)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6794)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5975)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
        at android.view.View.layout(View.java:16653)
        at android.view.ViewGroup.layout(ViewGroup.java:5437)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
        at android.view.View.layout(View.java:16653)
        at android.view.ViewGroup.layout(ViewGroup.java:5437)
        at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1255)
        at android.view.View.layout(View.java:16653)
        at android.view.ViewGroup.layout(ViewGroup.java:5437)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
        at android.view.View.layout(View.java:16653)
        at android.view.ViewGroup.layout(ViewGroup.java:5437)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
        at android.view.View.layout(View.java:16653)
        at android.view.ViewGroup.layout(ViewGroup.java:5437)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
        at android.view.View.layout(View.java:16653)
        at android.view.ViewGroup.layout(ViewGroup.java:5437)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
        at android.view.View.layout(View.java:16653)
        at android.view.ViewGroup.layout(ViewGroup.java:5437)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
        at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
        at android.view.View.layout(View.java:16653)
        at android.view.ViewGroup.layout(ViewGroup.java:5437)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
        at android.view.Choreographer$CallbackRecord.ru

活動_main.xml

<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/activity_main_drawer"
        app:headerLayout="@layout/nav_header_main" />
</androidx.drawerlayout.widget.DrawerLayout>

app_bar_main.xml

<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:orientation="vertical">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/color_red"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

content_main.xml

<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"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/app_bar_main">

    <include layout="@layout/home_main_menu"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

activity_main_drawer.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/Track"
            android:title="@string/text_track" />
        <item
            android:id="@+id/Landmark"
            android:title="@string/text_landmark" />
        <item
            android:id="@+id/ZoneTimer"
            android:title="@string/text_zone_timer" />
        <item
            android:id="@+id/StatsMenu"
            android:title="@string/text_stats" />
        <item
            android:id="@+id/SettingsFragment"
            android:title="@string/text_settings" />
    </group>
</menu>

主活動.java

@Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate()");
        // Do super class actions
        super.onCreate(savedInstanceState);

        // Set up the basic Android full screen properties
        initialScreenSetup();

        // Launch the Home Screen
        setContentView(R.layout.activity_main);

        // Set up Navigation Controls
        setupNavigationControl();
}


private void setupNavigationControl() {

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        // Set up the Navigation Components
        mNavController = Navigation.findNavController(this, R.id.nav_host_fragment);
        // Add the Destination Change Listener to monitor changes
        mNavController.addOnDestinationChangedListener(this::onDestinationChanged);


        DrawerLayout drawer = findViewById(R.id.drawer_layout);

           mAppBarConfiguration = new AppBarConfiguration.Builder(mNavController.getGraph())
                .setDrawerLayout(drawer)
                .build();

        mNavigationView = findViewById(R.id.nav_view);
        NavigationUI.setupActionBarWithNavController(this, mNavController, mAppBarConfiguration);
        NavigationUI.setupWithNavController(mNavigationView, mNavController);
    }

嘗試將整個項目遷移到 Androidx:轉到 android studio 菜單,然后選擇“重構”並單擊“遷移到 androidx”項 選擇備份並單擊重構 重構並運行您的項目

於是找了一位資深工程師朋友看了一下。 當然,他在 10 分鍾內就想通了。 我的問題是主題。 我想我用於抽屜的主題是引用與項目其余部分沖突的主題。 通常,指定的

@style/AppTheme.AppBarOverlay

@style/AppTheme.PopupOverlay

很好,但是這個特定的項目使用的是較舊的、相互矛盾的材料。 再次感謝任何花時間查看我的問題的人。 我喜歡堆棧溢出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM