android
runtime_error
ai_generated
true
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%Fix Rate
87%Confidence
1Evidence
2023-08-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Navigation Compose 2.6.0 | active | — | — | — |
| AndroidX Activity 1.7.0 | active | — | — | — |
| Kotlin 1.9.0 | active | — | — | — |
Root Cause
Navigation graph misconfiguration: action references a destination not defined in the same navigation graph or route mismatch.
generic中文
导航图配置错误:动作引用的目标未在同一导航图中定义或路由不匹配。
Official Documentation
https://developer.android.com/guide/navigation/navigation-getting-startedWorkarounds
-
90% success In NavHost composable, ensure all destinations are added: composable("destination1") { ... }. Then navigate using named routes: navController.navigate("destination2") instead of action IDs.
In NavHost composable, ensure all destinations are added: composable("destination1") { ... }. Then navigate using named routes: navController.navigate("destination2") instead of action IDs. -
85% success Regenerate navigation graph using Android Studio's Navigation Editor: right-click res/navigation/*.xml -> Open with Editor -> validate all actions and destinations.
Regenerate navigation graph using Android Studio's Navigation Editor: right-click res/navigation/*.xml -> Open with Editor -> validate all actions and destinations.
中文步骤
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.
Dead Ends
Common approaches that don't work:
-
Removing and re-adding the navigation graph resource file without checking IDs
60% fail
ID references may still be stale; requires verifying each action-destination mapping in the XML.
-
Hardcoding route strings instead of using generated NavDirections
75% fail
Bypasses type safety but still fails if route strings don't match graph; also breaks navigation arguments.