Kotlin and Android Development featuring Jetpack: Cannot reach Settings Fragment in Penny Drop (p. 177)

I think it’s just a shift in recommended styling, especially since you’re using Material Design 3. Most apps have gone away from using an action bar and instead handle settings and navigation elsewhere.

I just realized you mentioned this last time too. I looked a bit then and never found a sufficient answer. My thinking is that it’s thrown off by the nullability of previousPlayer and currentPlayer, but if you throw a debugger on that branch I bet it’ll work.

The extra odd part is that I tried the same thing in a Kotlin command line project to test out the code and the same issue doesn’t seem to show up there.

If you’re too troubled by the error, you can switch the when { ... } to skip the subject and instead do the comparisons manually:

when {
    status.playerId == result.previousPlayer?.playerId -> {
        status.copy(
            isRolling = false,
            pennies = status.pennies + (result.coinChangeCount ?: 0)
        )
    }
    status.playerId == result.currentPlayer?.playerId -> {
        status.copy(
            isRolling = !result.isGameOver,
            pennies = status.pennies +
                if (!result.playerChanged) {
                    result.coinChangeCount ?: 0
                } else 0
        )
    }
    else -> status
}

This will still have a warning telling you to use a subject, but it’s more subtle, at least. I really don’t think there’s an actual issue here, though, given that this is seen as fine and the other way isn’t while being the same logic.