Question
Fixing "navigation destination is unknown to this NavController" in Android Navigation
Question
I am using the Android Navigation Architecture Component, and when I try to navigate from one Fragment to another, I get this error:
java.lang.IllegalArgumentException: navigation destination XXX is unknown to this NavController
Most navigation in my app works correctly, but this specific transition fails.
I am using findNavController() inside a Fragment to access the NavController.
What does this error mean, and how can I fix it?
Short Answer
By the end of this page, you will understand what a NavController is, why Android Navigation throws the error "navigation destination is unknown to this NavController", and how to fix common causes such as using the wrong navigation graph, calling the wrong action, navigating from the wrong fragment, or referencing a destination that is not part of the active graph.
Concept
Android's Navigation Component works by connecting three main things:
- a
NavHostFragmentthat displays destinations - a
NavControllerthat manages navigation - a navigation graph that defines valid destinations and actions
When you call:
findNavController().navigate(...)
Android looks at the NavController currently attached to your fragment and checks its active navigation graph.
The error:
IllegalArgumentException: navigation destination XXX is unknown to this NavController
means that the destination or action you asked for is not known by the current NavController.
This usually happens for one of these reasons:
- the destination ID does not exist in the current graph
- the action is defined on a different fragment
- the fragment is using the wrong
NavController - the app has multiple navigation graphs or nested graphs, and you are navigating with the wrong one
- you are trying to navigate before the fragment is attached to the right host
Why this matters:
In real Android apps, navigation often becomes more complex with:
- nested graphs
Mental Model
Think of a NavController like a train operator managing one railway map.
- The navigation graph is the railway map.
- Each destination is a station.
- Each action is a valid track between stations.
- The
NavControlleronly knows the map it was given.
If you tell the operator to go to a station that is not on that map, it cannot continue and throws an error.
So this error does not usually mean the destination is invalid everywhere. It means:
the destination is invalid for this specific controller and its current graph.
Syntax and Examples
The most common navigation call inside a fragment is:
NavController navController = NavHostFragment.findNavController(this);
navController.navigate(R.id.someDestination);
Or with an action:
NavController navController = NavHostFragment.findNavController(this);
navController.navigate(R.id.action_firstFragment_to_secondFragment);
Example navigation graph
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/firstFragment">
<fragment
android:id="@+id/firstFragment"
android:name="com.example.FirstFragment"
android:label="First">
<action
android:id="@+id/action_firstFragment_to_secondFragment"
app:destination= />
Step by Step Execution
Consider this code:
NavController navController = NavHostFragment.findNavController(this);
navController.navigate(R.id.action_profileFragment_to_settingsFragment);
And this graph:
<fragment
android:id="@+id/profileFragment"
android:name="com.example.ProfileFragment">
<action
android:id="@+id/action_profileFragment_to_settingsFragment"
app:destination="@id/settingsFragment" />
</fragment>
<fragment
android:id="@+id/settingsFragment"
android:name="com.example.SettingsFragment" />
What happens step by step
findNavController(this)gets theNavControllerlinked to the current fragment.- Android checks which navigation graph that controller is using.
navigate(...)receives the IDaction_profileFragment_to_settingsFragment.
Real World Use Cases
This issue appears often in real Android apps in situations like these:
Multi-screen forms
A user moves through screens such as:
- personal details
- address
- confirmation
If one fragment tries to use an action defined for another step, navigation crashes.
Bottom navigation apps
Apps often use separate navigation graphs for each tab:
- Home
- Search
- Profile
A destination may exist in one tab's graph but not another. Using the wrong NavController causes this error.
Authentication flows
You may have:
- login graph
- main app graph
If code still refers to a destination from the login graph after switching to the main graph, the controller will not recognize it.
Dialogs and nested graphs
A dialog fragment or child fragment may try to navigate using a controller that belongs to a different host. The destination exists, but not in that controller's graph.
Reusable fragments
A fragment reused in different parts of an app may not always have the same actions available. Hardcoding a specific action can break in one flow while working in another.
Real Codebase Usage
In production code, developers usually avoid this error by using a few common patterns.
Prefer actions over raw destination IDs
Actions make navigation paths explicit.
navController.navigate(R.id.action_cartFragment_to_checkoutFragment);
This is often clearer than jumping directly to a destination.
Check the current destination before navigating
This helps prevent duplicate taps or invalid transitions.
NavController navController = NavHostFragment.findNavController(this);
if (navController.getCurrentDestination() != null
&& navController.getCurrentDestination().getId() == R.id.cartFragment) {
navController.navigate(R.id.action_cartFragment_to_checkoutFragment);
}
Use Safe Args when available
Safe Args generates typed navigation directions, which reduces mistakes with IDs and arguments.
// Example style
// NavDirections action = CartFragmentDirections.actionCartFragmentToCheckoutFragment();
// navController.navigate(action);
Keep graph ownership clear
In apps with nested navigation, teams usually decide:
- which
NavHostFragmentowns each flow - which graph each fragment belongs to
Common Mistakes
1. Using an action from the wrong fragment
Broken example:
NavHostFragment.findNavController(this)
.navigate(R.id.action_fragmentA_to_fragmentB);
This fails if the current fragment is not fragmentA.
How to avoid it:
- define the action on the correct source fragment
- only call that action from that fragment
2. Destination is not in the active graph
Broken example:
navController.navigate(R.id.settingsFragment);
This fails if settingsFragment exists in another navigation graph, not the current one.
How to avoid it:
- confirm the fragment belongs to the active graph
- use the correct
NavHostFragment
3. Using the wrong NavController
In apps with multiple hosts, findNavController() may return a controller different from the one you expect.
How to avoid it:
- make sure the fragment is inside the intended
NavHostFragment - if needed, retrieve the host explicitly from the activity
Example:
Comparisons
| Approach | What it means | When to use it | Risk |
|---|---|---|---|
navigate(R.id.destinationFragment) | Navigate directly to a destination | Simple graphs or global destinations | May be less explicit |
navigate(R.id.action_a_to_b) | Navigate using an action from the current fragment | Most fragment-to-fragment transitions | Fails if called from the wrong source |
findNavController() | Get controller from the current fragment/view | Standard case inside a fragment | Can be wrong in complex host setups |
Explicit NavHostFragment lookup | Get a specific controller by host ID | Multiple nav hosts or nested graphs | More verbose |
Action vs destination
Cheat Sheet
Core idea
The error means:
IllegalArgumentException: navigation destination ... is unknown to this NavController
- the
NavControllerdoes not know that destination or action - the ID is not valid in the current graph or current source destination
Quick fixes
- confirm the destination exists in the active navigation graph
- confirm the action is defined on the current fragment
- confirm you are using the correct
NavController - confirm the fragment is hosted by the expected
NavHostFragment - confirm you are not navigating after the fragment is no longer current
Common patterns
Get controller:
NavController navController = NavHostFragment.findNavController(this);
Navigate with action:
navController.navigate(R.id.action_a_to_b);
Navigate with destination:
navController.navigate(R.id.destinationB);
Check current destination:
FAQ
What does "destination is unknown to this NavController" mean in Android?
It means the NavController you are using cannot find the destination or action in its current navigation graph.
Why does some navigation work but one specific transition fail?
Usually because that one transition uses the wrong action, the wrong destination ID, or a destination that is not part of the active graph.
Should I use an action ID or a destination ID with navigate()?
Both are possible, but action IDs are often better for fragment-to-fragment navigation because they define a valid path from the current source.
Can multiple NavHostFragments cause this error?
Yes. If your fragment gets a NavController from the wrong host, the destination may exist in another graph but not in the current one.
How can I check which destination I am currently on?
Use navController.getCurrentDestination() and inspect its ID before navigating.
Can async callbacks cause this problem?
Yes. If a callback fires after the user leaves the fragment, the navigation request may no longer be valid for the current destination.
Does findNavController() always return the correct controller?
It works in the standard case, but in apps with nested hosts or multiple graphs, you may need to get the controller explicitly from the correct NavHostFragment.
Mini Project
Description
Build a small two-screen Android app using the Navigation Component. The project demonstrates how to define destinations in a navigation graph, create an action from one fragment to another, and safely navigate only when the current fragment is correct. This mirrors the real problem behind the error and helps you prevent it in practice.
Goal
Create a working app where HomeFragment navigates to DetailsFragment without triggering the "unknown to this NavController" error.
Requirements
- Create a navigation graph with
HomeFragmentas the start destination. - Add
DetailsFragmentto the same graph. - Define an action from
HomeFragmenttoDetailsFragment. - Add a button in
HomeFragmentthat triggers navigation. - Check the current destination before navigating.
Keep learning
Related questions
Accessing Kotlin Extension Functions from Java
Learn how Kotlin extension functions are compiled and how to call them correctly from Java with clear examples and common pitfalls.
Allow HTTP and HTTPS in Android 9 Pie with Network Security Configuration
Learn how Android 9 Pie handles cleartext HTTP traffic and how to allow HTTP and HTTPS safely using network security config.
Android AlarmManager Example: Scheduling Tasks with AlarmManager
Learn how to use Android AlarmManager to schedule tasks, set alarms, and handle broadcasts with a simple beginner example.