无法为类示例创建呼叫适配器。简单

rmuller:

我正在使用SimpleXml改造2.0.0-beta1。我想从REST服务中检索简单(XML)资源。使用SimpleXML编组/解组Simple对象可以正常工作。

使用此代码(转换为2.0.0之前的代码)时:

final Retrofit rest = new Retrofit.Builder()
    .addConverterFactory(SimpleXmlConverterFactory.create())
    .baseUrl(endpoint)
    .build();
SimpleService service = rest.create(SimpleService.class);
LOG.info(service.getSimple("572642"));

服务:

public interface SimpleService {

    @GET("/simple/{id}")
    Simple getSimple(@Path("id") String id);

}

我得到这个例外:

Exception in thread "main" java.lang.IllegalArgumentException: Unable to create call adapter for class example.Simple
    for method SimpleService.getSimple
    at retrofit.Utils.methodError(Utils.java:201)
    at retrofit.MethodHandler.createCallAdapter(MethodHandler.java:51)
    at retrofit.MethodHandler.create(MethodHandler.java:30)
    at retrofit.Retrofit.loadMethodHandler(Retrofit.java:138)
    at retrofit.Retrofit$1.invoke(Retrofit.java:127)
    at com.sun.proxy.$Proxy0.getSimple(Unknown Source)

我想念什么?我知道用Call工程包装返回类型但是我希望服务将业务对象作为类型返回(并在同步模式下工作)。

更新

添加了额外的依赖关系并.addCallAdapterFactory(RxJavaCallAdapterFactory.create())根据不同的答案提出建议后,我仍然收到此错误:

Caused by: java.lang.IllegalArgumentException: Could not locate call adapter for class simple.Simple. Tried:
 * retrofit.RxJavaCallAdapterFactory
 * retrofit.DefaultCallAdapter$1
Hosam Aly:

简短的答案:返回Call<Simple>您的服务界面。

看起来Retrofit 2.0正在尝试寻找一种为服务接口创建代理对象的方法。它希望您编写以下代码:

public interface SimpleService {
    @GET("/simple/{id}")
    Call<Simple> getSimple(@Path("id") String id);
}

但是,当您不想返回时,它仍然希望表现出色并且保持灵活性Call为了支持这一点,它具有a的概念,该概念CallAdapter应该知道如何将a调整Call<Simple>为a Simple

RxJavaCallAdapterFactory仅当您尝试返回时,使用才有用rx.Observable<Simple>

最简单的解决方案是返回CallRetrofit期望的结果。CallAdapter.Factory如果确实需要,也可以编写一个

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法调用适配器类中的构造函数

可动态创建的资源适配器

使用ReactiveCouchbaseRepository时发生IllegalArgumentException预期为类rxSingle找到反应式适配器,但无法

改造2.6.0异常:java.lang.IllegalArgumentException:无法为kotlinx.coroutines.Deferred创建调用适配器

无法为io.reactivex.Observable创建呼叫适配器

IllegalArgumentException:无法找到rx的呼叫适配器。可观察到的RxJava,Retrofit2

VBoxManage:错误:无法创建仅主机的适配器

Butterknife无法绑定到我的适配器类中

改装无法创建呼叫适配器

Retrofit 2.0:无法为类创建呼叫适配器

无法创建仅主机适配器

类扩展类的适配器

ISTIO MIXER ADAPTER-无法使OPA适配器与最简单的示例一起使用

无法创建用于Retrofit2.Response <...>的呼叫适配器

java.lang.IllegalArgumentException:无法为类创建调用适配器

从适配器类调用片段方法

适配器类的实现并创建MyMouseAdapter的实例

从适配器类启动FragmentActivity

为自己的框架创建新的诱惑适配器

简单适配器-NullPointerException

简单适配器空指针

为使用asynctask的searchview创建基本适配器

从适配器类设置OnItemClickListener

从适配器类扩展类

适配器类中的调用方法

创建通用类型适配器类不起作用

显示错误:无法为 io.reactivex.Observable<POJO> 创建调用适配器

尝试使用 Retrofit 发出 get 请求时,无法为类 java.lang.Object 创建调用适配器

为 sqlx 值创建适配器