调用其余api时出现上述错误。我同时使用retrofit2和RxJava。

ServiceFactory.java

public class ServiceFactory {
public static <T> T createRetrofitService(final Class<T> clazz, final String endpoint){

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(endpoint)
            //.addConverterFactory(GsonConverterFactory.create())

            .build();

    T service = retrofit.create(clazz);
    return service;
}

}

MovieService.java
public interface MovieService{
//public final String API_KEY = "<apikey>";
public final String SERVICE_END = "https://api.mymovies.org/3/";
@GET("movie/{movieId}??api_key=xyz")
Observable<Response<Movies>> getMovies(@Field("movieId") int movieId);

}

内部MainActivity
      MovieService   tmdbService = ServiceFactory.createRetrofitService(MovieService.class, MovieService.SERVICE_END);
    Observable<Response<Movies>> responseObservable = tmdbService.getMovies(400);
    responseObservable .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Subscriber<Response<Movies>>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(Response<Movies> moviesResponse) {

                }
            });

最佳答案

确保将implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'或正在使用的任何版本添加到依赖项中,然后使用该转换器配置改造:

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl(endpoint)
    .addConverterFactory(GsonConverterFactory.create())
    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
    .build();

更新了
RxJavaCallAdapterFactory重命名为RxJava2CallAdapterFactory。更改了上面的片段。

关于android - IllegalArgumentException : Could not locate call adapter for rx.可观察到的RxJava,Retrofit2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35233161/

10-10 13:59