Hi , we are getting this crash: `Fatal Exception: ...
# compose
v
Hi , we are getting this crash:
Fatal Exception: java.lang.IllegalArgumentException: No destination with route landing is on the NavController's back stack. The current destination is Destination(0x41295e74) route=neo_activation/{neoLaunchModeArg}/{neoTripIdArg}
at androidx.navigation.NavController.getBackStackEntry(NavController.kt:2230)
This is the code:
Copy code
fun NavGraphBuilder.neoBookingScreen(navController: NavController, onBackClick: () -> Unit) {
    composable(route = neoBookingRoute) { entry ->
        val neoViewModel: NeoViewModel = entry.sharedViewModel(navController)

        NeoBookingScreenRoute(neoViewModel = neoViewModel, onBack = onBackClick)
    }
}

@Composable
inline fun <reified T : ViewModel> NavBackStackEntry.sharedViewModel(
    navController: NavController
): T {
    val navGraphRoute = destination.parent?.route ?: return hiltViewModel()
    val pareEntry = remember(this) { navController.getBackStackEntry("landing") }
    return hiltViewModel(pareEntry)
}
I am not able to find the root cause here. we are using
androidx.navigation:navigation-compose
2.5.3 here
cc: @Ian Lake
👎 2
why thumbs down?
j
Why would you tag Ian in this?
v
I saw a few cases where ian answered: 1. https://stackoverflow.com/questions/78776233/error-when-using-popbackstack-no-destination-with-route-is-on-the-navcontrolle#:~:text=1 Answer&text=0-,remember(navController.,been%20popped%20off%20the%20graph.&text=Sign%20up%20to%20request%20clarification%20or%20add%20additional%20context%20in%20comments. 2. https://slack-chats.kotlinlang.org/api/link/1a905bbc-fd5b-42c7-9683-c8824ba05d78/506061
j
Anyways, the root cause is that there is no destination with the route
landing
in your backstack, so when you call
getBackStackEntry
looking for route
landing
it throws an exception
I don't think we can tell you why
landing
isn't in your backstack based on the code you shared, that'd be something worth looking into
v
we looked at the crash yesterday, tried to find the root cause but we were not, hence asked here
Even though it is clear that there is no destination with the route
landing
in backstack, but it is not possible to navigate to the
neo_activation
screen without
landing
.
The links I shared above are pointing to some what same issue.
j
The issue you linked points out using the incorrect backstack handle - I don't think that's your issue, since you aren't interacting with the current backstack entry directly
Again, I can't tell you why your
landing
route isn't on the backstack based on the code you shared, but it's a fact that it's not there
That could be because
landing
is a route on a different nav controller, or because it was popped from the backstack when navigating, or maybe it was never there to start with. There's not enough information in your post to narrow it down
It might be helpful for you to put a breakpoint or log whenever your backstack changes so that you know what gets added and removed when
c
@vicky7230 for next time and because you where curious about the 👎🏻
• Please do not ping or mention someone directly to get your questions answered, especially project owners, whether the project is Kotlin or other, unless they specifically indicate that you can.
https://kotlinlang.org/docs/slack-code-of-conduct.html#basic-usage-guidelines
🙌 1
v
NOTED