# Kotlin and Android Development featuring Jetpack: End Ch. 11 app runs but consistently crashes

**URL:** <https://forum.devtalk.com/t/kotlin-and-android-development-featuring-jetpack-end-ch-11-app-runs-but-consistently-crashes/135055>\
**Category:** PragProg Customers\
**Tags:** book-kotlin-and-android-development-featuring-jetpack, question\
**Created:** [6 December 2023 22:03 UTC](https://forum.devtalk.com/t/kotlin-and-android-development-featuring-jetpack-end-ch-11-app-runs-but-consistently-crashes/135055 "2023-12-06T22:03:19Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mfazio23](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mfazio23/32/528_2.png) [@mfazio23](https://forum.devtalk.com/u/mfazio23)\
**Post date:** [17 December 2023 16:09 UTC](https://forum.devtalk.com/t/kotlin-and-android-development-featuring-jetpack-end-ch-11-app-runs-but-consistently-crashes/135055/4 "2023-12-17T16:09:32Z")

</div>

Alright, this took me a bit since my original app still works as written, so I’m thinking this is due to a change in one of the navigation library. It’s seems like it’s trying to be helpful and re-create your `Fragment` automatically, but since it doesn’t know the `leaderType` it can’t.

I’d say the proper approach here is to send the `leaderType` as an argument to the `LeadersListFragment` rather than as a constructor parameter:

```plaintext
val leaderType = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    arguments?.getSerializable(LEADER_TYPE_KEY, LeaderType::class.java)
} else {
    arguments?.getSerializable(LEADER_TYPE_KEY) as? LeaderType
} ?: LeaderType.Batting

```

You can then remove `leaderType` from the constructor. Note that the extra version check logic is due to `arguments?.getSerializable(LEADER_TYPE_KEY)` being deprecated for API level 33, but our app supports lower versions.

You can also do this the easy way and make the constructor parameter nullable:

```plaintext
class LeadersListFragment(private val leaderType: LeaderType? = LeaderType.Batting)

```

Sorry this took a bit for me to get back to you!

---

_[View the full topic](https://forum.devtalk.com/t/kotlin-and-android-development-featuring-jetpack-end-ch-11-app-runs-but-consistently-crashes/135055)._
