I have bottom Navigation also I'm replaced the <fragment>
tag with FragmentContainerView
it gives me error about it does not have a NavController set on, then i was posted this question and fixed the problem, but I got this below error when orientation is changed and selecting item in Bottom Navigation
java.lang.IllegalStateException: You must call setGraph() before calling getGraph()
FragmentContainer
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" /
finding fragment
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.navigation_classes, R.id.navigation_schedule, R.id.navigation_settings
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
This is fixed as per the 2.2.0-rc03 release notes:
So make sure you are using
2.2.0-rc03
.use Navigation UI's latest vesion:
it fixed on new versions
Follow this link to fix this issue https://developer.android.com/jetpack/androidx/releases/navigation In simpler terms upgrade your dependencies to the ones below in app module
// Java
// Kotlin
// Dynamic Feature Module Support
// Testing Navigation
in project module under dependencies if you are using safe args
that fixed my issue..