Hello Everyone, I am getting an issue with Kotlin Hilt
Here's what I am doing right now, I have made one test class and needs to be injected in view model, Also wrote provides in component module.
Now I am injecting it in a viewmodel via @inject lateinit var test:TestInterface, now when I am trying to use the variable test, it gives the lateinit var has not initialized , can anyone suggest what is missing ?
j
James Harman
08/02/2021, 6:51 PM
I don’t see a lateinit var declared of type TestInterface, but you do it like this
Copy code
@Inject
lateinit var test:TestInterface
Or, if your view model is doing constructor injection like this
Copy code
@HiltViewModel
class MyViewModel @Inject constructor(
val test:TestInterface
) : ViewModel() {
}
James Harman
08/02/2021, 6:53 PM
Then in your fragment or activity
Copy code
@AndroidEntryPoint
class MyFragment: Fragment() {
val viewModel: MyViewModel by viewModesl()
}