google-developer-training/android-basics-kotlin-unscramble-app

Android Basics: ViewModel

this-click opened this issue · 1 comments

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-viewmodel?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-3%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-viewmodel#3

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?

  1. Go to GameFragment.kt
  2. Add private val viewModel: GameViewModel by viewModels() as instructed in codelab
  3. 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.
viewModel_error

forgot to add GameViewModel: ViewModel()