Supertype initialization is impossible without primary constructor

   **How can I solved it**

// How can resolve This error from kotlin fragment *

open class First : Fragment() {
}

// 'Which is showing in image Fragment() was not access' https://i.stack.imgur.com/Rcgl5.png


Solution 1:

Fragments are special classes in Android and they need primary constructor (and that constructor is after name of class). This constructor should by empty (if you declare any fields then you'll see warning, that you should not create Fragments with parameters).

So, all you need to compile your code is add brackets after fragment name:

class MyFragment() : Fragment() { /* some code here! remebmer about brackets after your MyFragment! */ }

Even more, you should avoid declaring any constructors with params. You should create your fragments by Companion.newInstance(someArgs: List<Arg>) : YourFragment. (where Companion is companion object of your Fragment).

How fragments should be initialized you can find here: https://stackoverflow.com/a/9245510/7508302

Solution 2:

Try adding constructor like this:

class First constructor() : Fragment() {
}

As you are using constructor below for passing fragmentManager there should be a default constructor when you are extending other class.