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

Apache License 2.0
103 stars 163 forks source link

Android Basics: Navigation backstack #44

Closed lbrunsvold closed 3 years ago

lbrunsvold commented 3 years ago

URL of codelab

https://developer.android.com/codelabs/basic-android-kotlin-training-navigation-backstack?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-4%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-navigation-backstack#2 In which task and step of the codelab can this issue be found?

  1. Implement Up button behavior

Describe the problem Click the back/up button the application quits/exits stops.

Steps to reproduce?

  1. Go to... any fragment other than the start fragment
  2. Click on... the back arrow or up arrow in the action bar.
  3. See error... kotlin.UninitializedPropertyAccessException: lateinit property navController has not been initialized at com.example.cupcake.MainActivity.onSupportNavigateUp(MainActivity.kt:52) Versions Android Studio version: 2020.3.1 Patch 2 API version of the emulator: 30.9.5-7820599

Additional information Include screenshots if they would be useful in clarifying the problem. package com.example.cupcake

import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupActionBarWithNavController

/**

}

lbrunsvold commented 3 years ago

removed val in front of navController in onCreate. The app runs fine.