andfun-kotlin-android-trivia
andfun-kotlin-android-trivia copied to clipboard
Adding the Up-Button causes app crashing
I had an issue with adding the Up-Button, where my App crashed with the message that my MainActivity would not have a NavController set.
I fixed this by accessing the navHostFragment directly: // Delete this line val navController = this.findNavController(R.id.myNavHostFragment)
//Replace it with: val navHostFragment = supportFragmentManager.findFragmentById(R.id.myNavHostFragment) as NavHostFragment val navController = navHostFragment.navController
//Continue with NavigationUI.setupActionBarWithNavController(this, navController)