0

I am using retrofit2 with rxjava2.

I have used mostly the latest library in my gradle and I have tried many methods for creating adapter .

I have also created some custom adapter but nothing seems to work with it

service :

    public static Retrofit getClient() {
        if (retrofit==null) {
            retrofit = new Retrofit.Builder().baseUrl(AppConstants.BASE_URL)

                    .addConverterFactory(GsonConverterFactory.create()).
                            addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();

        }
        return  retrofit;
    }

fragment code:
          ApiInterface apiInterface 
    =ApiClient.getClient().create(ApiInterface.class);
        apiInterface.getCategoryVideos(AppConstants.API_KEY)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())

                .subscribe(new Observer<Video>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Video value) {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

I have tried many adapters but no adapter is working . I am the log output is : Log Output

Any suggestion or solution is appreciated . I have also tried the solution in this link stackoverflow solution

Community
  • 1
  • 1
Sushrita
  • 725
  • 10
  • 29

1 Answers1

1

Try to change create client

public class MyClient {

private static MyClient instance;
private ApiInterface apiInterface;

private MyClient() {

    final Retrofit retrofit = new Retrofit.Builder().baseUrl(AppConstants.BASE_URL)
                                                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                                                    .addConverterFactory(GsonConverterFactory.create(gson))
                                                    .build();
    gitHubService = retrofit.create(ApiInterface.class);
}

public static MyClient getInstance() {
    if (instance == null) {
        instance = new MyClient();
    }
    return instance;
}


}

and fragment code

private Subscription subscription;

...

subscription = MyClient.getInstance().getCategoryVideos(AppConstants.API_KEY)
                               .subscribeOn(Schedulers.io())
                               .observeOn(AndroidSchedulers.mainThread())
                               .subscribe(new Observer<Video>() {
                                   @Override public void onCompleted() {
                                       Log.d(TAG, "In onCompleted()");
                                   }

                                   @Override public void onError(Throwable e) {
                                       e.printStackTrace();
                                       Log.d(TAG, "In onError()");
                                   }

                                   @Override public void onNext(Video value) {
                                       Log.d(TAG, "In onNext()");

                                   }
                               });
eurosecom
  • 2,932
  • 4
  • 24
  • 38