Skip to content

Class ‘kotlin.reflect.KClass’ is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler

After I converted my java code to Kotlin. There is an issue in this code ViewModelContactUs::class.java in this code part java is in red and does not work and says Returns a Java Class instance corresponding to the given KClass instance.

class ContactUsFragment : MVVMBaseFragment<ViewModelContactUs, FragmentContactUsBinding>(), CallBackContactUs {
    private var model: ModelContactUs? = null
    override fun getViewModel(): Class<ViewModelContactUs> {
        return ViewModelContactUs::class.java
    }
}

Answer

I removed this version below from my app/build/gradle file

  • ext.kotlin_version = ‘1.5.0-M1’

I added this version below from my app/build/gradle file

  • ext.kotlin_version = ‘1.4.0-rc’

it works fine,