2017-04-13 7 views
0

rxjava2でretrofit2を使用しています。エラー表示:io.reactivex.Observable用のコール・アダプタを作成できません。<POJO>

ほとんどの場合、私のグラデーションで最新のライブラリを使用していますが、アダプタを作成するための多くの方法を試しました。

私はまた、いくつかのカスタムアダプタを作成しましたが、何もそれが

サービスで動作するように思わない:私は多くのアダプタを試してみました

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() { 

        } 
       }); 

が、何のアダプタが作業していません。私は ですログ出力は: Log Output

です。 私もこのリンクでstackoverflow solution

答えて

0

をソリューションを試してみました、クライアント

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


} 

とフラグメントコード

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()"); 

            } 
           }); 
+0

私はコードを試してみましたあなたは提案しましたが、うまくいきません。 – Sushrita

+0

あなたのApiInterface.claは何ですか? ss? – eurosecom

+0

パブリックインターフェイスApiInterface {@GET( "category-video.php") Observable

関連する問題