hello everyone, I am currently stuck because Hilt ...
# android
a
hello everyone, I am currently stuck because Hilt cannot provide my ViewModel. When running tests, the ViewModel gets constructed correctly using a manual constructor call and the tests pass correctly, so I assume its an error with my Hilt configuration. I am using Compose and the viewModel() method. It crashes at runtime with the following error message:
Caused by: java.lang.InstantiationException: java.lang.Class<app.example.ui.screens.ExampleViewModel> has no zero argument constructor at java.lang.Class.newInstance(Native Method) at androidx.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:219) ... 199 more
My ViewModel looks like this:
Copy code
@HiltViewModel
class ExampleViewModel @Inject constructor(
    private val exampleRepository: ExampleRepository
) : BaseViewModel<Action, State>() {
Copy code
@Composable
fun ExampleScreen(viewModel: ExampleViewModel = viewModel()) {
m
like here they say you should use hiltViewModel extension
a
i mean i don't necessarily want to scope it to the navgraph. the docs state the following: https://developer.android.com/jetpack/compose/libraries#hilt