I am having an issue with the Android Navigation Architecture component when I try to navigate from one Fragment to another within a viewpager, I get this error:
java.lang.IllegalArgumentException: Navigation action/destination
com.gigaweb.mysales:id/action_mainFragment_to_addTransactionFragment cannot be found from the current
destination Destination(com.gigaweb.mysales:id/pagerFragment) label=fragment_pager class=com.gigaweb.mysales.PagerFragment
I have a viewpager which I use to navigate between two Fragments and it works just fine. the problem is that I have a button within one of the fragments, the button is also used to navigate to another Fragment using navcontroller, and when the button is clicked the app crashes and I get the error above.
Update This is the navGraph
As you can see the SignIn Fragment is the start Destination and there is an action liking it to the pagerFragment which serves as the host for the ViewPager
the way I want the app to work is:
When the app launches The signIn Fragment is shown ..... working
Navigate to PagerFragment when SignIn Button is clicked ..... working
Navigate between MainFragment and AdminFragment by swiping left or right ..... working
Navigate to AddTransactionFragment whin the FAB Button is clicked ..... NOT WORKING!! as the button is clicked the app crashes.
Update Here is the XML code for the Navigation Graph
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/signInFragment">
<fragment
android:id="@+id/signInFragment"
android:name="com.gigaweb.mysales.SignInFragment"
android:label="fragment_sign_in"
tools:layout="@layout/fragment_sign_in" >
<action
android:id="@+id/action_signInFragment_to_pagerFragment"
app:destination="@id/pagerFragment" />
</fragment>
<fragment
android:id="@+id/addTransactionFragment"
android:name="com.gigaweb.mysales.AddTransactionFragment"
android:label="AddTransactionFragment" >
<action
android:id="@+id/action_addTransactionFragment_to_mainFragment"
app:destination="@id/mainFragment" />
</fragment>
<fragment
android:id="@+id/mainFragment"
android:name="com.gigaweb.mysales.MainFragment"
android:label="MainFragment" >
<action
android:id="@+id/action_mainFragment_to_addTransactionFragment"
app:destination="@id/addTransactionFragment" />
</fragment>
<fragment
android:id="@+id/adminFragment"
android:name="com.gigaweb.mysales.AdminFragment"
android:label="AdminFragment" />
<fragment
android:id="@+id/pagerFragment"
android:name="com.gigaweb.mysales.PagerFragment"
android:label="fragment_pager"
tools:layout="@layout/fragment_pager" />
</navigation>