Cannot create an instance of class ViewModel

后端 未结 23 2760
[愿得一人]
[愿得一人] 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 12:58

    If you are using Hilt then don't forget to add these four dependencies.

        implementation "com.google.dagger:hilt-android:2.28-alpha"
        kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
        implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01'
        kapt "androidx.hilt:hilt-compiler:1.0.0-alpha01"
    

    Note:- If any of these dependencies are missing you will get Cannot create an instance of class ViewModel error

提交回复
热议问题