程序问答   发布时间:2022-05-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了错误“无法使用提供的参数调用以下任何函数。:大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决错误“无法使用提供的参数调用以下任何函数。:?

开发过程中遇到错误“无法使用提供的参数调用以下任何函数。:的问题如何解决?下面主要结合日常开发的经验,给出你关于错误“无法使用提供的参数调用以下任何函数。:的解决方法建议,希望对你解决错误“无法使用提供的参数调用以下任何函数。:有所启发或帮助;

我一直致力于在 Kotlin 中学习 RecyclerVIEws,但遇到了一个我似乎无法解决的特定错误:

val itemsHashSet = HashSet(category.items)

产生错误:

不能使用提供的参数调用以下函数。 ((MutableCollection..Collection?)) 其中 E = TypeVariable(E) 为乐趣 (c: (MutableCollection..Collection ?)): kotlin.collections.HashSet /* = java.util.HashSet / 定义在 kotlin.collections.HashSet (int) 其中 E = TypeVariable(E) for fun (initialCapacity: int): kotlin.collections.HashSet / = java.util.HashSet */ 在 kotlin.collections.HashSet 中定义

我尝试过更改格式,甚至用 Java 编写代码,然后在 AndroID studio 中将其转换都无济于事。

这是我一直坚持的课程:

class categorymanager(private val context: Context) {

    fun savecategory(category: categorymodel) {

        val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
        val editor = sharedPreferences.edit()

        val itemsHashSet = HashSet(category.items)

        editor.putStringSet(category.name,itemsHashSet)

        editor.apply()
    }

    fun retrIEveCategorIEs (): ArrayList<categorymodel> {

        val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
        val data = sharedPreferences.all

        val categorIEs = ArrayList<categorymodel>()

        for (item in data) {

            val category = categorymodel(item.key,arraylistof(item.value.toString()))

            categorIEs.add(category)

        }

        return categorIEs

    }
}

对不起,如果我是个白痴,这很明显,但我在这里找不到一个有意义的适用​​答案。任何帮助表示赞赏

编辑:

类别模型:

package com.pwneill.favoriteListapp

class categorymodel (name: String,items: ArrayList<String>) {

     val name = name
     val items = arrayOf(items)

}

解决方法

您可以像这样初始化 HashSet

val itemHashSet = hashSetOf(category.items)

大佬总结

以上是大佬教程为你收集整理的错误“无法使用提供的参数调用以下任何函数。:全部内容,希望文章能够帮你解决错误“无法使用提供的参数调用以下任何函数。:所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: