【发布时间】:2020-09-30 17:55:54
【问题描述】:
我尝试将 Retrofit 与 invoke() 方法一起使用,但发生错误
suspend {
Retrofit.Builder()
.baseUrl("https://api.openweathermap.org/data/2.5/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(WeatherApi::class.java)
.getPost("-33.8523341", "151.2106085", "***********API**********")
}.invoke()
getPost() 方法
@GET("onecall?units=metric")
fun getPost(
@Query("lat") lat: String,
@Query("lon") lon: String,
@Query("APPID") app_id: String
): WeatherData
错误
java.lang.IllegalArgumentException: Unable to create call adapter for
class com.example.weatherapp.data.responses.WeatherData
for method WeatherApi.getPost
【问题讨论】:
-
使用 Call
或 Deferred 。然而,Deferred 需要 kotlin.coroutines 库,但它减少了样板代码。