androidkotlinandroid-jetpack-composedagger-hilt

@HiltViewModel annotated class should contain exactly one @Inject or @AssistedInject annotated constructor


This is my view model code. When I run the app, I get the error "[Hilt] @HiltViewModel annotated class should contain exactly one @Inject or @AssistedInject annotated constructor."
`@HiltViewModel class SplashViewModel @Inject constructor() : ViewModel() {

} `

I checked it many times and found no errors in the code.


Solution

  • This is happen when the Fragment/Activity that is using the ViewModel is missing the @AndroidEntryPoint annotation

    make sure that

     @AndroidEntryPoint
     class SplashActivity : AppCompatActivity() {
     }
    
     // fragment
    
     @AndroidEntryPoint
     class SplashFragment: BaseFragment() {
     val viewModel: SampleFragmentViewModel by viewModels()
     }