Can someone please explain what is the root cause ...
# koin
o
Can someone please explain what is the root cause for this error? I mean, I know that it tells me I am using my ViewModel before onCreate (well, I am actually using it INSIDE onCreate)
g
Don't know if you're still having this issue, but the thing is that when the property is lazily initialized, you're using it inside
onCreate
, so it's only initialized after
onCreate
, but if it's eagerly initialized (using
= getViewModel
), the viewModel will be obtained during the class init. Class init is what runs before the constructor code (if any) when a class is instantiated, initializing all the properties that you declared.