为什么onNext()和其他方法不起作用?

时间:2018-02-16 17:06:49

标签: rx-java retrofit2 rx-java2 rx-android

我使用Retrofit2创建@GET响应,但onNext()onError()onComplete()不起作用。

retrofit = new Retrofit.Builder().baseUrl("https://gist.githubusercontent.com/MaxWBB/747f2eca800e05861bebc8f02ddb2721/raw/65673cae770b9b1fe8a668466868f1378e061f0d/").
            addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
    serverApi = retrofit.create(ServerApi.class);
    serverApi.getDatas().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new DisposableObserver<List<Client>>() {
        @Override
        public void onNext(List<Client> clients) {
            tv1.setText(String.valueOf(clients.size()));
            Log.d("getData()","Works");
        }

        @Override
        public void onError(Throwable e){
            Log.d("OnError()","error:"+String.valueOf(e));
        }

        @Override
        public void onComplete() {

        }
    });

0 个答案:

没有答案