Navigation error - This navigation graph is not referenced to any layout files?

You haven't set up for your <fragment> correctly - every <fragment> needs an android:name pointing to the Fragment class it is loading. In the case of Navigation, it must reference the androidx.navigation.fragment.NavHostFragment as per the Getting Start documentation:

<fragment
    android:id="@+id/nav_host_fragment"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:defaultNavHost="true"
    app:navGraph="@navigation/navigation"/>

Once you actually tie your navigation graph to a NavHostFragment, the error will go away.


If the accepted answer does not work initially, try "Make Project". Worked for me with <fragment/>


If other solutions haven't exactly worked, this worked for me, hopefully helps someone else as well

Especially if you work with Kotlin, check to see whether your dependencies have the same Kotlin versions working (Also anything that has an update or notification or something), then rebuild/sync, takes a bit to load, and at least for me seems to be working fine.

*If didn't work try invalidate catch/restart, who knows