【发布时间】:2020-07-05 10:50:51
【问题描述】:
我尝试使用入队回调,但它显示为“类型不匹配”之类的错误。
必需:回调>"
这正是我写的。
fun searchLocation(searchString: String){
showProgress.value = true
val retrofit = Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create())
.build()
val service = retrofit.create(WeatherNetwork::class.java)
service.getLocation(searchString).enqueue(object : Callback<List<Location>>{
override fun onFailure(call: Call<List<Location>>, t: Throwable) {
}
override fun onResponse(
call: Call<List<Location>>,
response: Response<List<Location>>
) {
}
})
}
May be it'll be more clear with the pic
UPD:天气网络
const val BASE_URL = "/My API/"
interface WeatherNetwork{
@GET ("search?")
fun getLocation(SearchString : String) : List<Location>
}
【问题讨论】:
-
确保你已经导入了 Retrofit Callback 接口,而不是其他同名的接口。
-
我确实做到了,没有任何效果,仍然显示此错误:(
-
可以添加接口
WeatherNetwork吗?我猜返回可能不是Call<List<Location>>