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
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.
官方文档
https://developer.android.com/guide/navigation/navigation-getting-started解决方案
-
In NavHost composable, ensure all destinations are added: composable("destination1") { ... }. Then navigate using named routes: navController.navigate("destination2") instead of action IDs. -
Regenerate navigation graph using Android Studio's Navigation Editor: right-click res/navigation/*.xml -> Open with Editor -> validate all actions and destinations.
无效尝试
常见但无效的做法:
-
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.
-
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.