您好,我收到一条未解决的参考入队消息,并且没有解决的选项。
回调是在片段中的按钮 setOnCLickListener 中进行的。
其他建议是将 Gradle 版本设置为 3.1.3(以前使用 3.6.1),但错误仍然存在。
btnSearch.setOnClickListener {
val service = RetrofitClientInstance.retrofitInstance?.create(GetFlightService::class.java)
val call = service?.getFlightData(
"QF",
"642",
"departing",
"2020",
"05",
"09",
"FS",
"xxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxxxxxxxxx") //appID and appKey x'd out :)
call?.enqueue(object : Callback<RetrievedFlightData>{
override fun onResponse(
call: Call<RetrievedFlightData>,
response: Response<RetrievedFlightData>
) {
if (response.code() == 200) {
val flightDataBody = response.body()!!
val flightData: FlightDTO = getFlightDTOData(flightDataBody)
}
}
override fun onFailure(call: Call<RetrievedFlightData>, t: Throwable) {
TODO("Not yet implemented")
Toast.makeText(activity,"Error: Callback faliure - ${t.message}", Toast.LENGTH_LONG).show()
}
})
}
界面为:
interface GetFlightService {
@GET ("/flex/schedules/rest/v1/json/flight/")
fun getFlightData(@Query("carrierFSCode") carrierFSCode: String,
@Query("flightNumber")flightNumber:String,
@Query("departing") departing:String,
@Query("year") year:String,
@Query("month") month:String,
@Query("day") day:String,
@Query("codeType") codeType: String,
@Query("appID") appID: String,
@Query("appKey") appKey:String
)
}
和客户端实例
object RetrofitClientInstance {
private var retrofit: Retrofit? = null
private const val BASE_URL = "https://api.flightstats.com"
//create a retrofit instance, only if it has not been created yet.
val retrofitInstance: Retrofit?
get() {
if (retrofit == null){
retrofit = retrofit2.Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
return retrofit
}
}
客户端实例工作正常,因为我进行了其他工作正常的调用。
另一个问题是我需要等待回复才能继续。我之前曾在另一个电话中使用过 newSingleThreadExecutor,但我知道这不是最佳做法。对此的任何帮助也将不胜感激。
谢谢
连接器