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

- **ID:** `android/navigation-compose-illegalargumentexception`
- **领域:** android
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Navigation Compose 2.6.0 | active | — | — |
| AndroidX Activity 1.7.0 | active | — | — |
| Kotlin 1.9.0 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **Removing and re-adding the navigation graph resource file without checking IDs** — ID references may still be stale; requires verifying each action-destination mapping in the XML. (60% 失败率)
- **Hardcoding route strings instead of using generated NavDirections** — Bypasses type safety but still fails if route strings don't match graph; also breaks navigation arguments. (75% 失败率)
