Was wondering how someone would deal with this.
I have a fragment that has a respective view model. That view model has an injected repo in its constructor. However when using "by viewModels()" to create the view model instance in my fragment I'm getting an error.
Example:
@Singleton
class MyViewModel @Inject constructor(val someRepo: SomeRepo) : ViewModel() { ... }
class MyFragment : BaseFragment(), Injectable {
val myViewModel: MyViewModel by viewModels()
...
}
Error: java.lang.RuntimeException: Cannot create an instance of class com.example.MVVM.ViewModel.MyViewModel
Has anyone got this to work without creating their own viewModelFactory?
MyViewModel
singleton, youronCleared()
will not work as expected. – Sheik