i am trying to get response but i am not getting it. also i am not getting any errors. what i am doing wrong? made POJO through jsonscema2Pojo.org
may be the way i am calling
@GET("16126940.json")
Observable <NewsFeed> getFinalData();
in soservice is wrong
i am dealing with below json
{
"by": "Doubleguitars",
"descendants": 70,
"id": 16126940,
"kids": [
16131536,
16131286,
16132328,
16132016,
16132256,
16131390,
16132386,
16132049,
16132088,
16132206,
16132895,
16131438,
16132082,
16132859,
16131517,
16131474,
16133112
],
"score": 173,
"time": 1515698746,
"title": "The Making of Apple’s Emoji",
"type": "story",
"url": "https://medium.com/@agzmn/the-making-of-apples-emoji-how-
designing-these-tiny-icons-changed-my-life-16317250a9ee"
}
my code in activity
public void loadNextDataFromApi(int itemCount) {
mService = ApiUtils.getSOService2();
}
public void loadAnswers(){
mService.getFinalData().subscribeOn(Schedulers.io()).
observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<NewsFeed>() {
@Override
public void onCompleted() { }
@Override
public void onError(Throwable e) { }
@Override
public void onNext(NewsFeed response) {
Log.e("response", "response------------------>" +
response.toString());
}
});
}
Retrofit Client
public class RetrofitClient {
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrl) {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
my Service
public interface SOService {
@GET("16126940.json")
Observable <NewsFeed> getFinalData();
}
in Utility i have kept method call
public static final String HTTP_JSON_URL = "https://hackernews.firebaseio.com/v0/item/";
public static SOService getSOService2() {
return RetrofitClient.getClient(HTTP_JSON_URL).create(SOService.class);
}
May be your error are ignored, As I can see your onError is blank. when you Hit service using RxJava and Retrofit. result will be successful or land in error. so onError should not be blank. put e.printStackTrace() at least. and also make sure you have called the method loadAnswers(). your provided code doesn't have that method called..
@Override
public void onError(Throwable e) {
e.printStackTrace()
}
I think you need to call the load answer method in below method.
public void loadNextDataFromApi(int itemCount) {
mService = ApiUtils.getSOService2();
loadAnswers();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.