Cannot create an instance of custom ViewModel

前端 未结 6 1474
孤街浪徒
孤街浪徒 2020-12-11 01:26

I am using dagger2 library. whenever I am trying to run my project is says not able to create instance of view model class.

main activity where I am trying to create

6条回答
  •  感动是毒
    2020-12-11 01:38

    I'm a proficient Android developer and I have used ViewModel 100s of times with no issue. Today I came across this issue. Spent hours and scrolled through various SO posts. Didn't get solved.

    Then I saw that the package name in which I have the ViewModel contains new. Like this:

    com.myapp.myfeature.new.feature

    I changed new to neww for testing like this: com.myapp.myfeature.neww.feature

    and it worked! I hope someone find it useful.

提交回复
热议问题