AbstractMethodError when using RxJavaCallAdapterFactory when retrofitting 2

I get this error:

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) 

when trying to use RxJavaCallAdapterFactory during modification. I am using com.squareup.retrofit:retrofit:2.0.0-beta1 and com.squareup.retrofit:adapter-rxjava:2.0.0-beta1 .

This is how I created the api interface:

 Retrofit retrofit = new Retrofit.Builder() .baseUrl(FORUM_SERVER_URL) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); mForumApi = retrofit.create(ForumApi.class); 

FORUM_SERVER_URL is a private static final String FORUM_SERVER_URL = "http://jsonplaceholder.typicode.com";

my interface method:

 @GET("/posts") public Observable<List<Post>> getPosts(); 

I call this via:

  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); } }); } 

getApi returns mForumApi
getPosts is where the error occurs, this is an API call

+5
source share
1 answer

It turned out to me that I used different beta versions of the components

Change (beta1 notification):

 compile 'com.squareup.retrofit:converter-simplexml:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1' 

to ( now beta2 )

 compile 'com.squareup.retrofit:converter-simplexml:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2' 

did it for me.

Stupid mistake, but yes ...

+11
source

Source: https://habr.com/ru/post/1233509/


All Articles