[英]Unable to create call adapter for retrofit.Call<java.util.List<Model.Object>>
My request fails doing a call 我的请求无法拨打电话
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(MyAPI.BASE_URL)
.addConverterFactory(JacksonConverterFactory.create())
.build();
// prepare call in Retrofit 2.0
MyAPI myAPI = retrofit.create(MyAPI.class);
**// Debug fails here on line below**
Call<List<Place>> call = myAPI.loadPlaces(3, "restaurant");
My interface 我的介面
// Base search url, trailing slash needed
String BASE_URL = "https://test.domain.com/";
@GET("place/search")
Call<List<Place>> loadPlaces(
@Query("count") int amountOfResults,
@Query("filter_category") String category);
Unfortunately this question did not helped, while most search results are using Gson and RxJava 不幸的是,尽管大多数搜索结果都使用Gson和RxJava,但这个问题没有帮助
Is there a way to get results without using a call? 有没有不用电话就可以得到结果的方法?
You can use rxJava library, for that you have to use specific call adapter factory during Retrofit instance creation: .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) . 您可以使用rxJava库,为此,在改造实例创建期间必须使用特定的调用适配器工厂:.addCallAdapterFactory(RxJavaCallAdapterFactory.create())。 Advantage of this method is that you can easily handle request in background and be notified about errors.
此方法的优点是您可以轻松地在后台处理请求并收到有关错误的通知。
Observable<List<Place>> pendingResult = myApi.getPlaces();
pendingResult.subscribeOn(Schedulers.io)
.map(places -> {
// pre- process places somehow
})
.subscribe(places -> {
// process result
}, error -> {
// handle error
}}
See this tutorial: https://medium.freecodecamp.com/rxandroid-and-retrofit-2-0-66dc52725fff#.5h0ecp5dg 请参阅本教程: https : //medium.freecodecamp.com/rxandroid-and-retrofit-2-0-66dc52725fff#.5h0ecp5dg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.