andfun-kotlin-android-trivia icon indicating copy to clipboard operation
andfun-kotlin-android-trivia copied to clipboard

Adding the Up-Button causes app crashing

Open Bellily opened this issue 1 year ago • 0 comments

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)

Bellily avatar Feb 04 '24 07:02 Bellily