android runtime_error ai_generated true

java.lang.IllegalArgumentException: 导航目标com.example:id/destination1不是动作com.example:id/action_to_destination2的有效NavDestination

java.lang.IllegalArgumentException: navigation destination com.example:id/destination1 is not a valid NavDestination for action com.example:id/action_to_destination2

ID: android/navigation-compose-illegalargumentexception

其他格式: JSON · Markdown 中文 · English
90%修复率
87%置信度
1证据数
2023-08-10首次发现

版本兼容性

版本状态引入弃用备注
Navigation Compose 2.6.0 active
AndroidX Activity 1.7.0 active
Kotlin 1.9.0 active

根因分析

导航图配置错误:动作引用的目标未在同一导航图中定义或路由不匹配。

English

Navigation graph misconfiguration: action references a destination not defined in the same navigation graph or route mismatch.

generic

官方文档

https://developer.android.com/guide/navigation/navigation-getting-started

解决方案

  1. In NavHost composable, ensure all destinations are added: composable("destination1") { ... }. Then navigate using named routes: navController.navigate("destination2") instead of action IDs.
  2. Regenerate navigation graph using Android Studio's Navigation Editor: right-click res/navigation/*.xml -> Open with Editor -> validate all actions and destinations.

无效尝试

常见但无效的做法:

  1. Removing and re-adding the navigation graph resource file without checking IDs 60% 失败

    ID references may still be stale; requires verifying each action-destination mapping in the XML.

  2. Hardcoding route strings instead of using generated NavDirections 75% 失败

    Bypasses type safety but still fails if route strings don't match graph; also breaks navigation arguments.