我收到此错误:
FATAL EXCEPTION: main E/AndroidRuntime: java.lang.AbstractMethodError: abstract method not implemented at retrofit.RxJavaCallAdapterFactory.get(RxJavaCallAdapterFactory.java) at retrofit.Retrofit.nextCallAdapter(Retrofit.java:189) at retrofit.Retrofit.callAdapter(Retrofit.java:175) at retrofit.MethodHandler.createCallAdapter(MethodHandler.java:45) at retrofit.MethodHandler.create(MethodHandler.java:26) at retrofit.Retrofit.loadMethodHandler(Retrofit.java:151) at retrofit.Retrofit$1.invoke(Retrofit.java:132) at $Proxy0.getPosts(Native Method)
在尝试使用RxJavaCallAdapterFactory进行改造时.我正在使用com.squareup.retrofit:retrofit:2.0.0-beta1和com.squareup.retrofit:adapter-rxjava:2.0.0-beta1.
这是我创建api接口的方法:
Retrofit retrofit = new Retrofit.Builder() .baseUrl(FORUM_SERVER_URL) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); mForumApi = retrofit.create(ForumApi.class);
FORUM_SERVER_URL是
private static final String FORUM_SERVER_URL =“http://jsonplaceholder.typicode.com”;
我的界面方法是:
@GET("/posts") public Observable<List<Post>> getPosts();
我叫它通过:
mForum.getApi() .getPosts() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<List<Post>>() { @Override public void onCompleted() {} @Override public void onError(Throwable e) {} @Override public void onNext(List<Post> posts) { mView.displayPosts(posts); } }); }
解决方法
对我来说,事实证明我正在使用不同的beta版本的组件
改变(注意beta1):
compile 'com.squareup.retrofit:converter-simplexml:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1'
到(现在beta2)
compile 'com.squareup.retrofit:converter-simplexml:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'
让它适合我.
愚蠢的错误,但是……