supportFragmentManager.commit in kotlin is not working

Tags: , , ,

Can anyone help me with this please? Inside my fragment supportFragmentManager.commit{} is not working. Android Studio is not recognizing this I don’t know what to do. I am working in kotlin project

enter image description here


That commit {} method (with the transaction in a lambda) is an extension function provided by the Fragment KTX library. If you haven’t already, you need to add this dependency in build.gradle:

dependencies {
    implementation "androidx.fragment:fragment-ktx:1.2.5"

and then Android Studio should automatically offer to fix the commit call by importing it. If it doesn’t (it can be awkward sometimes), add this to your imports:


and maybe these too, I don’t know if they’ll be necessary


you might need to remove some other matching imports so you’re just using the androidx versions

Source: stackoverflow