Hi. I'm not able to instantiate the ViewModel. I'm...
# android
d
Hi. I'm not able to instantiate the ViewModel. I'm getting the above error.
d
This is wrong place to ask. Your question is not specific to Kotlin. Read this first: https://developer.android.com/topic/libraries/architecture
d
Thank you for your reply. I don't get this error in Java. Only in Kotlin. Could you please help?
t
I really recommend that you read the Android Architecture Guide : your code has some serious issues, be it in Java or Kotlin. Android
ViewModel
should never keep a reference to a View, Fragment or Activity. Your crash is due to the fact that
CardViewModel
has a constructor parameter, so the framework is unable to instantiate it (only no-args constructors are allowed, unless you specify a factory). Check your implementation of
ViewModelProvider.Factory
for
CardViewModel
.
👍 3
d
@tseisel Thank you so much. I really missed the first part of ViewModel. I have read about it. Now I understand how it's actually works. Thanks again. ✌🏼