Cannot create an instance of class ViewModel

后端 未结 23 2704
[愿得一人]
[愿得一人] 2020-12-05 12:37

I am trying to write a sample app using Android architecture components and but even after trying for days I could not get it to work. It gives me the above exception.

23条回答
  •  情歌与酒
    2020-12-05 13:12

    If you are using Kotlin make sure to replace any annotationProcessor in build.gradle with kapt.

    Like:

    annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"

    Will become

    kapt "android.arch.persistence.room:compiler:$rootProject.roomVersion"

    and add

    apply plugin: 'kotlin-kapt' on top of the buidl.gradle file.

    Annotation Processing with Kotlin

提交回复
热议问题