Error: How to resolve this, getting this wiered error even though I am not doing any inject in view model
/Users/user/Documents/Personal/android-in-app-review-engine/Application/app/build/tmp/kapt3/stubs/debug/com/inappreview/code/MainActivityViewModel.java:7: error: [Hilt]
public final class MainActivityViewModel extends androidx.lifecycle.ViewModel {
^
@HiltViewModel annotated class should contain exactly one @Inject annotated constructor.
[Hilt] Processing did not complete. See error above for details.
MainActivity.kt
@AndroidEntryPoint
class MainActivity : AppCompatActivity(), InAppReviewView {
@Inject
lateinit var inAppReviewManager: InAppReviewManager
private val viewModel : MainActivityViewModel by viewModels()
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
viewModel.setInAppReviewView(this)
setOnClickListener()
}
private fun setOnClickListener() {
binding.startReviewProcess.setOnClickListener {
viewModel.startReview()
}
}
override fun showReviewFlow() {
val dialog = InAppReviewPromptDialog()
dialog.show(supportFragmentManager, null)
}
}
MainActivityViewModel.kt
@HiltViewModel
class MainActivityViewModel : ViewModel() {
private lateinit var inAppReviewView: InAppReviewView
/**
* Sets an interface that backs up the In App Review prompts.
* */
fun setInAppReviewView(inAppReviewView: InAppReviewView) {
this.inAppReviewView = inAppReviewView
}
/**
* Start In App Review
* */
fun startReview() {
inAppReviewView.showReviewFlow()
}
}
App.kt
@HiltAndroidApp
class App : Application()
CodePudding user response:
Since you are not injecting anything remove the @HiltViewModel
, you only need that when you want to inject something into your ViewModel