简体   繁体   English

无法创建用于改装的呼叫适配器。 <java.util.List<Model.Object> &gt;

[英]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.

相关问题 java.lang.IllegalArgumentException:无法为接口改造创建调用适配器。Call - java.lang.IllegalArgumentException: Unable to create call adapter for interface retrofit.Call Retrofit和Rxjava“无法为java.util.List创建转换器 <Model> ” - Retrofit and Rxjava “Unable to create converter for java.util.List<Model>” 无法为 class java.lang.Object - ZB9794896D299A7854021A 创建呼叫适配器 - Unable to create call adapter for class java.lang.Object - Retrofit IllegalArgumentException:无法为 java.util.List 创建转换器<ModelClass>将 SimpleXmlConverter 与改造 2.0 一起使用时 - IllegalArgumentException: Unable to create converter for java.util.List<ModelClass> when using SimpleXmlConverter with retrofit 2.0 无法为java.util.List创建转换器Retrofit 2.0.0-beta2 - Unable to create converter for java.util.List Retrofit 2.0.0-beta2 Retrofit 无法创建呼叫适配器 - Retrofit is unable to create call adapter 调用retrofit.Call &lt;&gt;时发生NullPointerException - NullPointerException on calling retrofit.Call<> 翻新无法创建呼叫适配器 - Retrofit Unable to create call adapter 无法为 class java.lang.Object 创建呼叫适配器,同时尝试使用 ZB973C40896D3769A 发出请求 - Unable to create call adapter for class java.lang.Object while trying to make get request using Retrofit 如何在Retrofit2 converter-simplexml中调试“ java.lang.IllegalArgumentException:无法为java.util.List创建转换器”? - How to debug “java.lang.IllegalArgumentException: Unable to create converter for java.util.List” in Retrofit2 converter-simplexml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM