您必须先调用setGraph()才能调用getGraph() [英] You must call setGraph() before calling getGraph()
问题描述
我有底部导航,也用FragmentContainerView
替换了<fragment>
标记,这给我关于未设置NavController的错误,然后我被发布了
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:您必须在调用getGraph()之前先调用setGraph()
java.lang.IllegalStateException: You must call setGraph() before calling getGraph()
FragmentContainer
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" /
发现片段
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)
推荐答案
此问题已根据
与 因此请确保您使用的是 So make sure you are using 这篇关于您必须先调用setGraph()才能调用getGraph()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!FragmentContainerView
一起使用时,NavHostFragment
现在可以在配置更改后正确地还原图形. ( b/143752103 )
NavHostFragment
now correctly restores the graph after a configuration change when used with FragmentContainerView
. (b/143752103)2.2.0-rc03
.2.2.0-rc03
.