类型不匹配:推断类型是 <no name provided> 但 Callback<Post!>!预计
Type mismatch: inferred type is <no name provided> but Callback<Post!>! was expected
我有这个功能
val client = NetworkService()
val call = client.getService().getAllPost()
call.enqueue(object : Callback<ArrayList<Post>>{
override fun onFailure(call: Call<ArrayList<Post>>, t: Throwable) {
Toast.makeText(this@MainActivity, "Get post failed", Toast.LENGTH_LONG).show()
}
override fun onResponse(
call: Call<ArrayList<Post>>,
response: Response<ArrayList<Post>>) {
response.body()?.let{
post ->
adapter?.updateData(post)
}?: kotlin.run {
Toast.makeText(this@MainActivity, "Get post failed", Toast.LENGTH_LONG).show()
}
}
})
}
* 出现错误 *
Type mismatch: inferred type is <no name provided> but Callback<Post!>! was expected
在call.enqueue(object : Callback<ArrayList<Post>>
回调 ArrayList 不想使用对象,idk why
请帮助它
您可能导入了一个与实际要导入的包同名的包。
资料来源:这只是发生在我身上。有时当 IntelliJ 自动导入新的 类.
时,我没有仔细阅读包名称
检查导入包是来自android还是androidx
您的代码中可能有:
fun call(@Body body: Any): Call<Post>
return 的值不是您的错误中描述的 Call<Post>
:
Type mismatch: inferred type is but Callback<Post!>! was expected
是Call<List<Post>>
:
fun call(@Body body: Any): Call<List<Post>>
(请注意,我已将 Any
作为您参数的类型,因为我不知道它的类型。
确保导入是
import retrofit2.Callback
而不是import javax.security.auth.callback.Callback
我有这个功能
val client = NetworkService()
val call = client.getService().getAllPost()
call.enqueue(object : Callback<ArrayList<Post>>{
override fun onFailure(call: Call<ArrayList<Post>>, t: Throwable) {
Toast.makeText(this@MainActivity, "Get post failed", Toast.LENGTH_LONG).show()
}
override fun onResponse(
call: Call<ArrayList<Post>>,
response: Response<ArrayList<Post>>) {
response.body()?.let{
post ->
adapter?.updateData(post)
}?: kotlin.run {
Toast.makeText(this@MainActivity, "Get post failed", Toast.LENGTH_LONG).show()
}
}
})
}
* 出现错误 *
Type mismatch: inferred type is <no name provided> but Callback<Post!>! was expected
在call.enqueue(object : Callback<ArrayList<Post>>
回调 ArrayList 不想使用对象,idk why
请帮助它
您可能导入了一个与实际要导入的包同名的包。
资料来源:这只是发生在我身上。有时当 IntelliJ 自动导入新的 类.
时,我没有仔细阅读包名称检查导入包是来自android还是androidx
您的代码中可能有:
fun call(@Body body: Any): Call<Post>
return 的值不是您的错误中描述的 Call<Post>
:
Type mismatch: inferred type is but Callback<Post!>! was expected
是Call<List<Post>>
:
fun call(@Body body: Any): Call<List<Post>>
(请注意,我已将 Any
作为您参数的类型,因为我不知道它的类型。
确保导入是
import retrofit2.Callback
而不是import javax.security.auth.callback.Callback