Android Basics: ViewModel
this-click opened this issue · 1 comments
this-click commented
In which task and step of the codelab can this issue be found?
Task 4. Add a ViewModel, step Attach the ViewModel to the Fragment, Initialize the GameViewModel using the by viewModels() Kotlin property delegate:
private val viewModel: GameViewModel by viewModels()
Describe the problem
App won't build because of the type mismatch at GameViewModel initialization
Steps to reproduce?
- Go to GameFragment.kt
- Add private val viewModel: GameViewModel by viewModels() as instructed in codelab
- See error Type mismatch: inferred type is ViewModel but GameViewModel was expected
Versions
Android Studio version: Chipmunk | 2021.2.1 Patch 2
API version of the emulator: 31
Additional information
Include screenshots if they would be useful in clarifying the problem.
this-click commented
forgot to add GameViewModel: ViewModel()