Hello Everyone, I am getting an issue with Kotlin ...
# android
v
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
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() {
}
Then in your fragment or activity
Copy code
@AndroidEntryPoint
class MyFragment: Fragment() {
  val viewModel: MyViewModel by viewModesl()
}
v
Thank you it's working now