None of the following functions can be called with the arguments supplied.
时间: 2024-05-31 19:09:37 浏览: 11
This error message is commonly seen in programming languages like Python, Java, or C++, and it usually indicates that the function is expecting different arguments than what is being provided.
For example, if a function expects two arguments, but only one is provided, or if the types of the arguments do not match what the function is expecting, this error message may appear.
To fix this error, you should check the documentation or the source code of the function to see what arguments it expects, and make sure to provide the correct number and type of arguments.
相关问题
Line 3: Char 26: error: none of the following functions can be called with the arguments supplied: public infix fun <T, R> Array<out String>.zip(other: Array<out ???>): List<Pair<String, ???>> defined in kotlin.collections public infix fun <T, R> Array<out String>.zip(other: Iterable<???>): List<Pair<String, ???>> defined in kotlin.collections val pairs = names.zip(heights) // 合并为 Pair 类型的数组 ^ Line 4: Char 34: error: unresolved reference: it pairs.sortByDescending { it.second } // 按照身高降序排序 ^ Line 5: Char 28: error: unresolved reference: it return pairs.map { it.first }.toTypedArray() // 提取排序后的 names
这个错误是因为在第三行中,你尝试将一个字符串数组(names)与一个未知类型的数组(heights)合并成一个Pair类型的数组。你需要将heights的类型指定为与names相同的字符串数组类型。
修改第三行为:
```
val pairs = names.zip(heights as Array<out String>) // 将 heights 转换为 String 数组类型
```
第四行和第五行中的错误是因为你引用了一个未定义的变量it。你需要将it替换为lambda表达式参数中的参数名。
修改第四行为:
```
pairs.sortByDescending { pair -> pair.second } // 使用参数名 pair 替换 it
```
修改第五行为:
```
return pairs.map { pair -> pair.first }.toTypedArray() // 使用参数名 pair 替换 it
```
完整的代码如下:
```kotlin
fun sortByHeight(names: Array<String>, heights: Array<Int>): Array<String> {
val pairs = names.zip(heights as Array<out String>)
pairs.sortByDescending { pair -> pair.second }
return pairs.map { pair -> pair.first }.toTypedArray()
}
```
isdirectory(): incompatible function arguments. the following argument types
isdirectory()函数的参数类型不匹配。这个函数通常是用来判断一个路径是否是一个目录的。
根据错误消息"incompatible function arguments. the following argument types",意思是说某个参数类型是不兼容的,导致函数调用出错。
通常来说,使用isdirectory()函数时,需要传入一个路径作为参数。路径可以是一个字符串,表示文件系统中的一个路径,或者是一个Path对象,表示文件系统中的一个路径。
如果出现错误消息"incompatible function arguments. the following argument types",通常是因为传入了不可识别的参数类型。比如,可能传入了一个整数、浮点数、布尔值或其他类型的参数,而不是一个路径。
要解决这个问题,我们需要确保传入参数的类型是正确的。可以检查函数调用处传入参数的类型,确保其为字符串或Path对象。
另外,还要注意,使用isdirectory()函数之前,需要确保所操作的路径存在,并且能够被访问到,否则可能会抛出其他异常。确保文件系统中的路径正确,并且具有正确的访问权限,可以避免出现函数调用错误。
总结起来,为了解决isdirectory()函数的错误消息"incompatible function arguments. the following argument types",我们需要检查函数调用处传入参数的类型,确保其为字符串或Path对象,并且确保路径存在且可访问。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)