I am trying to access my room database viewModel in a Repo file rather than a Composable, because I want to use some data in my MainViewModel. I am getting a mismatch when trying to access the viewModel. What could I be doing wrong? It works absolutely fine when I call it within a Composable.
I'm getting this: "Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun <reified VM : ViewModel> ComponentActivity.viewModels(noinline factoryProducer: (() → ViewModelProvider.Factory)? = ...): Lazy<TypeVariable(VM)> defined in androidx.activity"
s
Scott Kruse
03/12/2022, 5:06 PM
You're not in an activity, check out the error message.
ComponentActivity.viewModels is the function definition
Just guessing, but you probably want to restructure your dependencies here
n
Nat Strangerweather
03/12/2022, 5:09 PM
Ah ok, thanks for this!
I'll try and work it out
🙂
s
Scott Kruse
03/12/2022, 5:09 PM
No problem 🤙
a
Adam Powell
03/12/2022, 5:23 PM
For the future, this is a good question for #android