You must call setGraph() before calling getGraph()
You'll get this same error if you are like me and forget to add to your FragmentContainerView
app:navGraph="@navigation/nav_graph"
app:defaultNavHost="true"
This is fixed as per the 2.2.0-rc03 release notes:
NavHostFragment
now correctly restores the graph after a configuration change when used withFragmentContainerView
. (b/143752103)
So make sure you are using 2.2.0-rc03
.