Navigation component Kotlin - cannot be found from the current destination

Cyd :

I have a fragment A,B,C. Its okay when navigating from A -> B, but from B -> C it crashes.

Here is my Navigation

enter image description here

Here is my navigation code

 categoryProductItemListAdapter.setOnItemClickListener {
        val action = CategoryProductItemsDirections.actionCategoryProductItems2ToProductItem(null, it)
        navController = Navigation.findNavController(requireView())
        navController?.navigateUp()
        navController?.navigate(action)
    }

Here is the XML code for the destination to productItem

<fragment
    android:id="@+id/categoryProductItems2"
    android:name="com.sample.store.main.dashboard.ui.ui.home.categoryitems.CategoryProductItems"
    android:label="CategoryProductItems"
    tools:layout="@layout/fragment_category_product_items">
    <argument
        android:name="category_global"
        app:argType="com.sample.store.data.globalmodels.response.categories.Category" />
    <action
        android:id="@+id/action_categoryProductItems2_to_productItem"
        app:destination="@id/productItem"
        app:enterAnim="@anim/enter_from_right"
        app:exitAnim="@anim/exit_to_right"
        app:popEnterAnim="@anim/fragment_open_enter"
        app:popExitAnim="@anim/fragment_fade_exit" />
</fragment>

And here is the error:

java.lang.IllegalArgumentException: Navigation action/destination com.sample.store.full:id/action_categoryProductItems2_to_productItem cannot be found from the current destination Destination(id/navigation_home) label=Home class=com.sample.store.main.dashboard.ui.ui.home.mainui.HomeFragment

I don't know what happened, but it seems that the navController is looking for the "navigation_home"

Indiana :

Firstly you should not pass requireView() when trying to retrieve your Nav controller - navController = Navigation.findNavController(requireView()). You should be passing the actual Navigation Host Fragment instance.

Secondly the issue is being caused because you are trying to call a Navigation path from B -> C, when on fragment A.

Your direction path is from B -> C

val action = CategoryProductItemsDirections.actionCategoryProductItems2ToProductItem(null, it)

But you navigate up first so you are actually now on Fragment A when trying to execute the navigation:

navController?.navigateUp()
navController?.navigate(action)

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Navigation Architecture Component - Activities

Access $refs from other components not in the same level as current component

Navigation Component .popBackStack() with arguments

wix react native navigation v2 | how to push new screen to current screen from side drawer component

Android: Kotlin: custom webView - cannot be invoked as a function. The function 'invoke()' is not found

Cannot load css from assets in component

Detect navigation back from component in named router outlet

React Load Component on Navigation

Add enter animation to start destination in android navigation component

Cannot access to the redux state from class component

Navigate with PopUpTo but not knowing what you root destination is - Navigation Architecture Component

Cannot access props from function inside React Component

Dynamic feature module navigation IllegalStateException: The included <navigation>'s id is different from the destination id

NativeScript-Vue - Navigation from outside component

React Navigation Is there a way to refer to a navigator from the parent component?

react native component has no access to props - TypeError: Cannot read property ‘navigation’ of undefined

AJAX + Spring MVC: Cannot find destination

How can I navigate from an activity to another using Navigation Component and removing the first activity from the stack?

ReactNative: Component inline and for navigation

SSIS Script Task Destination Component Not Completing

Trying to display image from database in datagrid column Exception "The component cannot be found"

Angular component not found from external link in reset password feature

React route: how to obtain the current route key from the component

Unable to pass value from FragmentOne to FragmentTwo even after setting argument value for destination fragment in navigation

Navigation Component: how to navigate from activity to a fragment

Compose Navigation - navigation destination ... is not a direct child of this NavGraph

IllegalArgumentException: Navigation action/destination cannot be found from the current destination Destination [Navigation Error]

Current item cannot be removed from the list because there is no current item

Cannot display items by pasing value from context component