Reputation: 4221
I created a new Android project in Kotlin. I also created a new Navigation Drawer Activity using the wizard. As always nothing works out of the box.
The following lines showed a compilation error:
val navController = findNavController(R.id.nav_host_fragment)
I had to import the method and add the first argument 🤦🏻♂:
import androidx.navigation.Navigation.findNavController
...
val navController = findNavController(this, R.id.nav_host_fragment)
Now the next line shows a compilation error:
val navController = findNavController(this, R.id.nav_host_fragment)
return navController.navigateUp(appBarConfiguration) // does not compile
Error:
"Too many arguments for public open fun navigateUp(): Boolean defined in androidx.navigation.NavController"
I have the following dependency in my gradle configuration:
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
It contains the NavController.kt
file, which contains the extension function. Where's the problem?
Upvotes: 4
Views: 8194
Reputation: 121
I tried to reproduce your problem but it works for me. Check if you have proper imports
Instead of yours:
import androidx.navigation.findNavController
I have:
import androidx.navigation.Navigation.findNavController
And for navigateUp:
import androidx.navigation.ui.navigateUp
Upvotes: 7