我想尝试新的导航库.遵循本指南后,我在运行时遇到错误:
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists, is public, and has an empty constructor that is public
Run Code Online (Sandbox Code Playgroud)
在资源文件中activity_home.xml.这个文件很简单:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.home.HomeActivity">
<fragment
android:id="@+id/fragment_navigation_host"
android:name="androidx.navigation.fragment.NavHostFragment"
app:defaultNavHost="true"
app:navGraph="@navigation/navigation_home" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我查看了源代码,NavHostFragment并注意到它android.support.v4.app.Fragment …
android android-fragments kotlin android-architecture-components android-architecture-navigation