I am using Navigation Editor in Android Studio to implement Safe Args
.
I am accepting arguments in one fragment as
<fragment
android:id="@+id/gameWonFragment"
android:name="com.example.android.navigation.GameWonFragment"
android:label="@string/android_trivia"
tools:layout="@layout/fragment_game_won">
<action
android:id="@+id/action_gameWonFragment_to_gameFragment"
app:destination="@id/gameFragment"
app:popUpTo="@+id/titleFragment">
</action>
<argument
android:name="numQuestions"
app:argType="integer"
android:defaultValue="0" />
<argument
android:name="numCorrect"
app:argType="integer"
android:defaultValue="0" />
</fragment>
And in my Fragment, I am sending arguments as
view.findNavController().navigate(GameFragmentDirections.actionGameFragmentToGameWonFragment(numQuestions, questionIndex))
But, GameFragmentDirections.actionGameFragmentToGameWonFragment()
doesn't want to accept arguments. I tried Clean Project
and Rebuild Project
.
This is throwing:
Too many arguments for @NonNull public open fun actionGameFragmentToGameWonFragment(): GameFragmentDirections.ActionGameFragmentToGameWonFragment defined in com.example.android.navigation.GameFragmentDirections
This issue is fixed by removing the android:defaultValue
tag.
So -
<argument
android:name="numQuestions"
app:argType="integer"/>
<argument
android:name="numCorrect"
app:argType="integer"/>
Then Rebuild Project
after making changes.
This was answered in a similar post here - https://stackoverflow.com/a/60807951/11615237
Basically, you probably need to use the Kotlin version of the plugin like this apply plugin: "androidx.navigation.safeargs.kotlin"
.
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