无法从无线电浏览器信息获取数据

时间:2018-10-09 11:48:30

标签: android api retrofit2 rx-java2

我正在遵循此tutorial来获取能够实现代码的数据,但是当我尝试从this API中获取数据时,我无法获取任何数据。我将如何获取尝试的数据 无线电客户端

public class RadioClient {
private static final String GITHUB_BASE_URL = "http://www.radio-browser.info/";

private static RadioClient instance;
private RadioServer gitHubService;

private RadioClient() {
    final Gson gson =
            new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(GITHUB_BASE_URL)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build();
    gitHubService = retrofit.create(RadioServer.class);
}

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



public  io.reactivex.Observable<List<Datahelper>> getStarredRepos(){
    return gitHubService.getStarredRepositories();
}
}

radioServer

public interface RadioServer {
@GET("webservice/xml/stations")
io.reactivex.Observable<List<Datahelper>> getStarredRepositories();
}

我如何称呼活动中的仓库

private void getStarredRepos() {

    disposable = RadioClient.getInstance()
            .getStarredRepos()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                    new Consumer<List<Datahelper>>() {
                        @Override
                        public void accept(List<Datahelper> gitHubRepos) throws Exception {

                            recyclerAdapter.setGitHubRepos(gitHubRepos);
                        }
                    },
                    new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable t) throws Exception {

                        }
                    }
            );


}

我正在使用Retrofit2。任何提示都会有所帮助。谢谢。

0 个答案:

没有答案