I am trying to adapt to my own app, one of the sample projects of "Android Studio Giraffe Essential"(namely "navigationDemo") that provides an example of how to navigate from one fragment (FirstFragment) to the other (SecondFragment) by clicking a button in the first fragment (and the example app works perfectly well on my device).
To assign the navigation action to the button, they use a method from a class which name is built on the class name itself: FirstFragmentDirections.MainToSecond
Trying to adapt the above to my app, I am unable to find an equivalent to ".MainToSecond" that is accepted by the IDE. And the name of the calss depending on the name of the fragments, it is difficult to seek for help on line.
This is the code of the sample app I am trying to adapt:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.button.setOnClickListener {
val action: FirstFragmentDirections.MainToSecond =
FirstFragmentDirections.mainToSecond()
//action.message = binding.userText.text.toString()
Navigation.findNavController(it).navigate(action)
}
}
Note that the navigation graph sets as action id mainToSecond:
<?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/navigation_graph"
app:startDestination="@id/firstFragment">
<fragment
android:id="@+id/firstFragment"
android:name="com.ebookfrenzy.navigationdemo.FirstFragment"
android:label="fragment_first"
tools:layout="@layout/fragment_first" >
<action
android:id="@+id/mainToSecond"
app:destination="@id/secondFragment" />
</fragment>
<fragment
android:id="@+id/secondFragment"
android:name="com.ebookfrenzy.navigationdemo.SecondFragment"
android:label="fragment_second"
tools:layout="@layout/fragment_second" >
<argument
android:name="message"
app:argType="string"
android:defaultValue="No Message" />
</fragment>
</navigation>
Here is the same code adapted to my app:
I tried several combinations instead of .BaseMotToJeu, like the original ".MainToSecond" or "Action_fragmentBaseMots_tofragmentJeu" which was the default id of the action in the navigationgraph editor. But nothing works and the IDE makes no suggestion.

The problem I had looks very much like a bug of safeargs or whatever. I noticed that if you add an argument in the second fragment section of the navigation graph like that:
even if you don't make any use of the argument, it solves the problem.
By the way, in the above code, the string "message" remains in red without any consequence on building nor running. And this happens to be a known bug of the Android Studio. Are the two problems linked...