Android在后台关闭应用程序后,NavigationUI.setupActionBarWithNavController会导致应用程序在启动时崩溃

Android在后台关闭应用程序后,NavigationUI.setupActionBarWithNavController会导致应用程序在启动时崩溃,android,kotlin,navigation,crash,Android,Kotlin,Navigation,Crash,在activity onCreate方法中,我使用以下方法设置actionBar以显示和处理向上按钮上的点击: val navController = this.findNavController(R.id.exerciseNavHostFragment) NavigationUI.setupActionBarWithNavController(this, navController) 当我将我的应用程序发送到后台时,它会被操作系统杀死,当我启动应用程序时,它会崩溃。再次尝试启动应用程序时,它

在activity onCreate方法中,我使用以下方法设置actionBar以显示和处理向上按钮上的点击:

val navController = this.findNavController(R.id.exerciseNavHostFragment)
NavigationUI.setupActionBarWithNavController(this, navController)
当我将我的应用程序发送到后台时,它会被操作系统杀死,当我启动应用程序时,它会崩溃。再次尝试启动应用程序时,它会毫无问题地运行。崩溃仅发生在终止后的第一次应用程序启动时

应用程序在NavigationUI.setupActionBarWithNavController行上崩溃,并显示以下崩溃日志(崩溃前检查navController显示图形为空):

我没有发现任何类似的问题,所以,我是新的安卓开发,任何帮助我可能会做错事是感谢

我使用最新的依赖项进行导航:

// Navigation
    implementation "android.arch.navigation:navigation-fragment-ktx:2.3.0"
    implementation "android.arch.navigation:navigation-ui-ktx:2.3.0"
该应用程序有一个底部导航栏,可以在活动之间切换,每个活动都有自己的navHostFragment。 以下是我的主要活动布局xml:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <fragment
        android:id="@+id/exerciseNavHostFragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:navigationBarColor="@color/navigationBarColor"
        app:layout_constraintBottom_toTopOf="@+id/navigation"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0"
        app:defaultNavHost="true"
        app:navGraph="@navigation/exercise_navigation" />

    <include
        android:id="@+id/navigation"
        layout="@layout/item_bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

您使用了错误的依赖项。当你使用

implementation "android.arch.navigation:navigation-fragment-ktx:2.3.0"
implementation "android.arch.navigation:navigation-ui-ktx:2.3.0"
您实际使用的不是Navigation 2.3.0,而是最新版本的
android.arch.Navigation
-Navigation 1.0.0

您需要更新依赖项以匹配上的依赖项,并使用
androidx.navigation

implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"

您是否在布局XML中使用了
app:navGraph
,其中声明了
NavHostFragment
?如果您可以包含活动的布局XML,这将非常有帮助。@ianhanniballake yes,添加了XML,并简要描述了应用程序的导航架构,如果您认为需要更多信息来查找问题,请告诉我。
implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"