MainActivity.kt in 04_UIState in ZIP file has duplicate view model initialization

Assuming that the code in 04_UIState is meant to reflect the state of the application at the end of the chapter, the original ViewModel initialization code has been left in. Line 23 has the “by lazy” init:

    private val quizViewModel: QuizViewModel by lazy {
        ViewModelProviders.of(this).get(QuizViewModel::class.java)
    }

but at line 32, the code used earlier in the chapter that should have been deleted still appears:

        val provider: ViewModelProvider = ViewModelProviders.of(this)
        val quizViewModel = provider.get(QuizViewModel::class.java)
        Log.d(TAG, "Got a QuizViewModel: $quizViewModel")

Lines 32-34 should be deleted.

1 Like

This post was flagged by the community and is temporarily hidden.