android - Error inflating class Fragment, when adding navGraph attribute
问题描述
I know there are a few questions and answers about this problem, but none of the solutions fixed my problem. I get an
android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class fragment
error, when I add the navGraph attribute with the navigation xml-file.
So here is my activity_login.xml (with the fragment container):
<?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"
tools:context=".LoginActivity">
<fragment
android:name="androidx.navigation.fragment.NavHostFragment"
android:id="@+id/loginFragmentContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:navGraph="@navigation/nav_graph"/>
</androidx.constraintlayout.widget.ConstraintLayout>
The nav_graph.xml is just as empty as it is generated.
Here are the important dependencies for the fragment:
implementation "androidx.navigation:navigation-fragment:2.3.0"
implementation "androidx.navigation:navigation-ui:2.3.0"
implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"
implementation "androidx.navigation:navigation-dynamic-features-fragment:2.3.0"
androidTestImplementation "androidx.navigation:navigation-testing:2.3.0"
implementation "androidx.fragment:fragment:1.2.5"
implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"
When I do not include this line app:navGraph="@navigation/nav_graph" in my activity_login.xml -layout, I do not get an error. What's my mistake?
I am using Android Studio 4.1 Canary 10
Please just ask if I need to share more code or information... Thanks in advance and best regards!
解决方案
您的导航图需要至少有一个目的地 - 您的图表的起始目的地和用户根据入门指南扩充图表时看到的第一个屏幕。
推荐阅读
- php - PHPWord DOMDocument::loadXML():开始和结束标记不匹配:实体中的 br 行 1 和 p,行:1
- javascript - SyntaxError: missing ) 在参数列表 php javascript 之后
- node.js - 使用 OpenID Connect 提供者进行身份验证后如何在客户端上创建会话
- django - Django - 基于类的 TemplateView 的动态模型
- c# - 如何克隆 Visual Studio 项目而无需一次又一次地重写所有代码
- c# - foreach 没有很好地阅读 .descendants 并在 if 之前转到 else 语句
- python - 通过将以前的列与熊猫错误相加来创建新列
- debugging - `kubectl debug` 在 1.20 上挂起,启用了功能门
- java - 如何用逗号分割字符串,但从第二个逗号
- javascript - 从离子选择中获取价值并将其存储在本地存储中