Skip to content
This repository has been archived by the owner on Aug 31, 2020. It is now read-only.

help me #4

Closed
diorslau opened this issue Mar 1, 2019 · 8 comments
Closed

help me #4

diorslau opened this issue Mar 1, 2019 · 8 comments

Comments

@diorslau
Copy link

diorslau commented Mar 1, 2019

Hello, I wrote it according to your code, and then it ran wrong. I hope I can help me.

Caused by: java.lang.IllegalStateException: Could not find Navigator with name "keep_state_fragment". You must call NavController.addNavigator() for each navigation type.

@diorslau
Copy link
Author

diorslau commented Mar 1, 2019

code:

    NavHostFragment navHostFragment = (NavHostFragment) mFragmentManager.findFragmentById(R.id.fragment);
    KeepStateNavigator navigator = new KeepStateNavigator(this, navHostFragment.getChildFragmentManager(), R.id.fragment);

    NavController navController = navHostFragment.getNavController();
    navController.getNavigatorProvider().addNavigator(navigator);

    NavigationUI.setupWithNavController(mBinding.navigation, navController);

@STAR-ZERO
Copy link
Owner

Probably, you need to call navController.setGraph.

@STAR-ZERO
Copy link
Owner

Let me close. If you have any problem, please tell me.

@gerardoepitacio
Copy link

gerardoepitacio commented Apr 30, 2019

@diorslau did you solve this?

Update
Try removing
app:navGraph="@navigation/nav_graph"
in nav_host_fragment item.

@tianxm
Copy link

tianxm commented Oct 23, 2019

@diorslau did you solve this?

Update
Try removing
app:navGraph="@navigation/nav_graph"
in nav_host_fragment item.

great, this work

@DenisMakovskyi
Copy link

DenisMakovskyi commented Apr 2, 2020

Try to extend NavHostFragment by your custom fragment StatefulNavHostFragment: NavHostFragment() and override onCreateNavController, where you can add your naviagator.

This problem is probably occurs because nav inflater is trying to inflate your graph, and at this moment he know nothing about your navigator.

@iamsr
Copy link

iamsr commented Apr 17, 2020

If anyone still facing the problem please remove the app:navGraph="" from your host fragment and while seting up this navigator first set navigator then set graph.

@netcyrax
Copy link

Hey! Thanks for the pointers, but when I remove app:navGraph then val navHostFragment = parentFragmentManager.findFragmentById(R.id.navHostView)!! throws null pointer exception. Does anyone encountered this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants