Android Basics: ViewModel
IgorPonomarev opened this issue · 1 comments
URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-viewmodel
In which task and step of the codelab can this issue be found?
Step 7
Describe the problem
The line "if (wordsList.contains(currentWord)) {" in getNextWord function causes an error because wordsList is null
/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.unscramble, PID: 8782
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.contains(java.lang.Object)' on a null object reference
at com.example.android.unscramble.ui.game.GameViewModel.getNextWord(GameViewModel.kt:38)
Steps to reproduce?
Run the app
Versions
Android Studio version: 2021.3.1 Patch 1
API version of the emulator: 33
Additional information
Include screenshots if they would be useful in clarifying the problem.
Nevermind. Its because i wrote init{} part before wordsList declaration