java - mainactivity 62 er logcat
问题描述
我有以下错误:
java.lang.RuntimeException: Unable to start Activity
ComponentInfo{com.example.cn/com.example.cn.MainActivity}:
android.view.InflateException: Binary XML file line #69: Binary XML file line #69: Error inflating class androidx.support.design.widget.NavigationView
主要活动.xml:
<?xml version="1.0" encoding="utf-8"?>
<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/drawable_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingBottom="5dp"
tools:context="com.example.cn.MainActivity"
android:paddingStart="10dp"
tools:ignore="RtlSymmetry">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/main_page_toolbar"
layout="@layout/app_bar_layout">
</include>
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="673dp"
android:layout_alignTop="@+id/main_page_toolbar"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="58dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/all_user_post_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<ImageButton
android:id="@+id/add_new_post_button"
android:layout_width="165dp"
android:layout_height="57dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="246dp"
android:layout_marginLeft="246dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:background="@color/colorPrimaryDark"
android:scaleType="centerCrop"
android:src="@drawable/add_post_high"
android:contentDescription="@string/app_name" />
</RelativeLayout>
<androidx.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginBottom="3dp"
app:menu="@menu/navigation_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
解决方案
Afaik,AndroidX 中没有androidx.support.design.widget.NavigationView
类。但您可以com.google.android.material.navigation.NavigationView
用作替代品。
因此,更改以下内容:
<androidx.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginBottom="3dp"
app:menu="@menu/navigation_menu" />
至:
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginBottom="3dp"
app:menu="@menu/navigation_menu" />
阅读NavigationView了解更多详情。
推荐阅读
- python - 当输出 w,h 为负时计算 yolo v1 损失
- c++ - 为什么这两个代码给出不同的输出?// bits.c float_i2f
- docker - Docker Node-Alpine:puppeteer-core@1.20.0 在 page.pdf() 中抛出错误
- android - Android中的Google登录集成登录错误DEVELOPER ERROR
- java - 如何处理 ajax 确认对话框的是或否
- eclipse - Kotlin 无法使用 Eclipse 工作区分辨率
- amazon-web-services - 如何在 VPC 中有多个子网的数据库实例上只选择 1 个子网?
- javascript - laravel 按钮意外移动
- wpf - 使用 WPF 在 PowerShell 中创建窗口
- tensorflow - Keras 自定义损失函数产生奇怪的结果