Cannot create an instance of class ViewModel

后端 未结 23 2753
[愿得一人]
[愿得一人] 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条回答
  •  旧时难觅i
    2020-12-05 12:58

    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.

提交回复
热议问题