相关疑难解决方法(0)

无法为类example.Simple创建调用适配器

我正在使用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"));
Run Code Online (Sandbox Code Playgroud)

服务:

public interface SimpleService {

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

}
Run Code Online (Sandbox Code Playgroud)

我得到这个例外:

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)
Run Code Online (Sandbox Code Playgroud)

我错过了什么?我知道通过Call作品包装返回类型.但是我希望服务将业务对象作为类型返回(并在同步模式下工作).

UPDATE

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

Caused by: java.lang.IllegalArgumentException: Could not locate call adapter for class simple.Simple. Tried:
 * retrofit.RxJavaCallAdapterFactory
 * retrofit.DefaultCallAdapter$1
Run Code Online (Sandbox Code Playgroud)

java rest simple-framework retrofit

67
推荐指数
9
解决办法
6万
查看次数

Android,无法使用Retrofit和RxJava 2构建应用程序

这是依赖项

compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'io.reactivex.rxjava2:rxjava:2.0.7'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
Run Code Online (Sandbox Code Playgroud)

当我尝试运行应用程序时,我收到此错误

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
Run Code Online (Sandbox Code Playgroud)

com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:在APK META-INF/rxjava.properties File1中复制的重复文件:C:\ Users\abondarenco.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava\2.0.7\21734c0092a5d3c3ec99510e50c1ff76bdf0c65a\rxjava-2.0.7.jar File2:C:\ Users\abondarenco.gradle\_caches\modules-2\files-2.1\io.reactivex\rxjava\1.2.0\42bfaf64c94f3848ebf5cf1c2ea4ec9d1b3ac6c8\rxjava-1.2.0.jar

我尝试运行应用程序没有adapter-rxjava它工作,但当我添加适配器它说有重复文件,它下载RxJava 1 ...

android rx-java retrofit rx-java2

2
推荐指数
1
解决办法
810
查看次数

标签 统计

retrofit ×2

android ×1

java ×1

rest ×1

rx-java ×1

rx-java2 ×1

simple-framework ×1