您必须先调用setGraph()才能调用getGraph() [英] You must call setGraph() before calling getGraph()

查看:989
本文介绍了您必须先调用setGraph()才能调用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)

推荐答案

此问题已根据FragmentContainerView一起使用时,

NavHostFragment现在可以在配置更改后正确地还原图形. ( b/143752103 )

NavHostFragment now correctly restores the graph after a configuration change when used with FragmentContainerView. (b/143752103)

因此请确保您使用的是2.2.0-rc03.

So make sure you are using 2.2.0-rc03.

这篇关于您必须先调用setGraph()才能调用getGraph()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆