androidx导航:@NonNull公共打开乐趣的参数过多 [英] androidx Navigation: Too many arguments for @NonNull public open fun

查看:82
本文介绍了androidx导航:@NonNull公共打开乐趣的参数过多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Studio中的导航编辑器来实现 Safe Args .

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>

在我的片段中,我以

view.findNavController().navigate(GameFragmentDirections.actionGameFragmentToGameWonFragment(numQuestions, questionIndex))

但是, GameFragmentDirections.actionGameFragmentToGameWonFragment()不想接受参数.我尝试过 Clean Project Rebuild Project .

But, GameFragmentDirections.actionGameFragmentToGameWonFragment() doesn't want to accept arguments. I tried Clean Project and Rebuild Project.

这是抛出:

Too many arguments for @NonNull public open fun actionGameFragmentToGameWonFragment(): GameFragmentDirections.ActionGameFragmentToGameWonFragment defined in com.example.android.navigation.GameFragmentDirections

推荐答案

此问题已通过删除 android:defaultValue 标记来解决.

This issue is fixed by removing the android:defaultValue tag.

所以-

<argument
    android:name="numQuestions"
    app:argType="integer"/>
<argument
    android:name="numCorrect"
    app:argType="integer"/>

进行更改后,然后重建项目.

这篇关于androidx导航:@NonNull公共打开乐趣的参数过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆