Android导航组件:java.lang.IllegalStateException:恢复期间的未知目标

时间:2019-02-02 18:13:27

标签: android kotlin android-jetpack android-architecture-navigation

我正在使用Android的AAC导航组件,并且已按照我的登录信息实现了条件导航,如这篇文章所述:Navigation Architecture Component - Login screen

现在一切似乎都可以正常工作,但是在导航到登录屏幕并成功登录然后导航回到主屏幕之后,旋转时应用崩溃,并出现以下错误:

--------- beginning of crash
2019-02-02 13:08:28.423 6030-6030/uk.co.victoriajanedavis.chatapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: uk.co.victoriajanedavis.chatapp, PID: 6030
    java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.victoriajanedavis.chatapp/uk.co.victoriajanedavis.chatapp.presentation.ui.main.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4699)
        at android.app.ActivityThread.-wrap18(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
     Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
     Caused by: java.lang.IllegalStateException: unknown destination during restore: uk.co.victoriajanedavis.chatapp:id/friendsFragment
        at androidx.navigation.NavController.onGraphCreated(NavController.java:483)
        at androidx.navigation.NavController.setGraph(NavController.java:459)
        at androidx.navigation.NavController.setGraph(NavController.java:424)
        at androidx.navigation.NavController.setGraph(NavController.java:406)
        at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:226)
        at androidx.fragment.app.Fragment.performCreate(Fragment.java:2414)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:844)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1129)
        at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3132)
        at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:133)
        at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:345)
        at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:324)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:141)
        at uk.co.victoriajanedavis.chatapp.presentation.ui.main.MainActivity.onCreate(MainActivity.kt:22)
        at android.app.Activity.performCreate(Activity.java:7009)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4699)
        at android.app.ActivityThread.-wrap18(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
2019-02-02 13:08:28.423 6030-6030/uk.co.victoriajanedavis.chatapp E/AndroidRuntime:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

这是我的nav_graph.xml(负责登录流程的ID是@ + id / action_friendsFragment_to_loginFlowGraph,@ + id / action_loginFragment_to_chatFlowGraph,@ + id / action_signupFragmentFragment_to_chatFlowGraph):

<?xml version="1.0" encoding="utf-8"?>
<navigation
    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/nav_graph"
    app:startDestination="@id/chatFlowGraph">

    <!-- Chat Flow (nested graph) -->
    <navigation android:id="@+id/chatFlowGraph"
        app:startDestination="@id/friendsFragment">

        <fragment
            android:id="@+id/friendsFragment"
            android:name="uk.co.victoriajanedavis.chatapp.presentation.ui.friends.FriendRequestsToolbarFragment"
            android:label="fragment_friends"
            tools:layout="@layout/fragment_friend_requests_toolbar">

            <action
                android:id="@+id/action_friendsFragment_to_loginFlowGraph"
                app:destination="@id/loginFlowGraph"
                app:popUpTo="@id/chatFlowGraph"
                app:popUpToInclusive="true"
                app:enterAnim="@anim/slide_in_bottom"
                app:exitAnim="@anim/fade_out"
                app:popEnterAnim="@anim/fade_in"
                app:popExitAnim="@anim/slide_out_bottom"/>

            <action
                android:id="@+id/action_friendsFragment_to_chatFragment"
                app:destination="@id/chatFragment"/>

            <action
                android:id="@+id/action_friendsFragment_to_friendRequestsFragment"
                app:destination="@id/friendRequestsFragment"
                app:enterAnim="@anim/grow_in_top_right"
                app:exitAnim="@anim/fade_out"
                app:popEnterAnim="@anim/fade_in"
                app:popExitAnim="@anim/grow_out_top_right"/>
        </fragment>

        <fragment
            android:id="@+id/chatFragment"
            android:name="uk.co.victoriajanedavis.chatapp.presentation.ui.chat.ChatFragment"
            android:label="fragment_chat"
            tools:layout="@layout/fragment_chat" />
    </navigation>

    <!-- Login/Register Flow (nested graph) -->
    <navigation android:id="@+id/loginFlowGraph"
        app:startDestination="@id/loginFragment">

        <fragment
            android:id="@+id/loginFragment"
            android:name="uk.co.victoriajanedavis.chatapp.presentation.ui.login.LoginFragment"
            android:label="fragment_login"
            tools:layout="@layout/fragment_login">

            <action
                android:id="@+id/action_loginFragment_to_chatFlowGraph"
                app:destination="@id/chatFlowGraph"
                app:popUpTo="@id/loginFlowGraph"
                app:popUpToInclusive="true"/>

            <action
                android:id="@+id/action_loginFragment_to_signupFragment"
                app:destination="@id/signupFragment"
                app:enterAnim="@anim/slide_in_right"
                app:exitAnim="@anim/slide_out_left"
                app:popEnterAnim="@anim/slide_in_left"
                app:popExitAnim="@anim/slide_out_right"/>

        </fragment>

        <fragment
            android:id="@+id/signupFragment"
            android:name="uk.co.victoriajanedavis.chatapp.presentation.ui.signup.SignupFragment"
            android:label="fragment_signup"
            tools:layout="@layout/fragment_signup">

            <action
                android:id="@+id/action_signupFragment_to_chatFlowGraph"
                app:destination="@id/chatFlowGraph"
                app:popUpTo="@id/loginFlowGraph"
                app:popUpToInclusive="true"/>

        </fragment>

    </navigation>

    <!-- FriendRequestsFragment -->
    <fragment
        android:id="@+id/friendRequestsFragment"
        android:name="uk.co.victoriajanedavis.chatapp.presentation.ui.friendrequests.FriendRequestsFragment"
        android:label="fragment_friend_requests"
        tools:layout="@layout/fragment_friend_requests">
        <action
            android:id="@+id/action_friendRequestsFragment_to_sendFriendRequestFragment"
            app:destination="@id/sendFriendRequestFragment"
            app:enterAnim="@anim/slide_in_bottom"
            app:exitAnim="@anim/fade_out"
            app:popEnterAnim="@anim/fade_in"
            app:popExitAnim="@anim/slide_out_bottom"/>
    </fragment>

    <!-- SendFriendRequestFragment -->
    <fragment
        android:id="@+id/sendFriendRequestFragment"
        android:name="uk.co.victoriajanedavis.chatapp.presentation.ui.friendrequests.sent.send.SendFriendRequestFragment"
        android:label="fragment_send_friend_request"
        tools:layout="@layout/fragment_send_friend_request" />

</navigation>

编辑:使用最新的导航组件版本1.0.0-alpha11

2 个答案:

答案 0 :(得分:1)

此错误已在导航组件的1.0.0-beta01版本中修复。

答案 1 :(得分:0)

即使在1.0.0-beta01之后,看起来该错误仍然存​​在

从变更日志中,我们可以在2.1.0-alpha04中看到它已解决