Cannot create an instance of class ViewModel

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

    If you used viewmodel inside your activity check that your activity extends "DaggerAppCompatActivity" or not

    For instance

    public class UserComments extends AppCompatActivity 
    

    change this to

    public class UserComments extends DaggerAppCompatActivity
    

提交回复
热议问题