Navigation Drawer
In this when I click Saved Result it shows all the saved results with date.
The image showing saved results in SavedResultsFragment
Navigation Layout
When I click on any item it should show all the details of that clicked item in ShowSavedResltsFragment but instate app crashes and IllegalStateException is raised with fragment class was not set.
The image showing navigation layout and code
The image showing code logic where trying to switch to ShowResultsFragment from SavedResultFragment
I'm using safe args and all but only issue is faced when I try to navigate between SavedResultFragment to ShowSavedResultsFragment. I tried to search official documentation and Stack Overflow but didn't found anything which I was facing. Official documentation gives a hint that navHostfragment is not implemented properly then this can trigger above exception but I'm using their official documentation but only thing I have done here is navigating to a Fragment through Navigation Drawer and then from that fragment trying to navigate to another fragment and this is where it breaks.
Image showing exception Edit: NavHostFragment code
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
</data>
<merge>
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/myNavHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navVew"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
</merge>
</layout>
The declaration of your ShowSavedResultsFragment inside your nav graph doesn't have a name attribute attached to it.
If you look at the SavedResultFragment declaration, you'll notice it has a name attribute.
Add a name attribute to your ShowSavedResultsFragment declaration. The value of the name attribute should be the package name of the ShowSavedResultsFragment class .(dot) the name of the class. Something like com.xxx.yyy.savedresult.ShowSavedResultsFragment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With