Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Android Kotlin Fundamentals codelab: 5.1 ViewModel: requireArguments() instead of arguments!! #460

@vgoetz

Description

@vgoetz

Name of the Codelab or Codelab URL
Android Kotlin Fundamentals: 5.1 ViewModel
https://codelabs.developers.google.com/codelabs/kotlin-android-training-view-model/index.html?index=..%2F..android-kotlin-fundamentals#7

Describe the problem
wrong variable

In which lesson and step of the codelab can this issue be found?

  • 5.1 ViewModel
    -- 8. Task: Use a ViewModelFactory
    --- Step 8.) "In ScoreFragment, inside OnCreateView(), after [..]
    viewModelFactory = ScoreViewModelFactory(ScoreFragmentArgs.fromBundle(arguments!!).score)"

How to reproduce and solve the problem?
arguments!! can't be resolved.
Replace arguments!! with requireArguments()
Result:
viewModelFactory = ScoreViewModelFactory(ScoreFragmentArgs.fromBundle(requireArguments()).score)

Versions

  1. What version of Android Studio are you using? --> 4.1
  2. What API level are you targeting? --> 30

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions