0

I am new in learning kotlin and trying to start a android application project with it.

After I created a project, I got stuck in the first line of code I wrote..

Type mismatch error

So this is my code and error.

I made MainFragment class extend Fragment and passed it's instance to beginTransaction().add() method.

I know that Fragment! is a platform type and it is type of Java class instantiated.

But I think there is no reason Fragment type doesn't math Fragment!.

How do I solve this problem?

+) I also tried MainFragment() as Fragment as FragmentTransaction won't Compile in Kotlin Android Project says, but it didn't work.

+) Also tried newInstance() in companion object

Hyun I Kim
  • 589
  • 1
  • 3
  • 14

1 Answers1

1

In your fragment MainFragment,
use import android.support.v4.app.Fragment in place of import android.app.Fragment. and then it should work.

niketshah09
  • 470
  • 3
  • 8