Reputation: 269
I am trying to get values from a web using retrofit and rxAndroid but onNext doesn't called. Here, my classes:
public class ForumService {
private static final String FORUM_SERVER_URL = "http://192.168.1.104:8080/curso-fullstack/symfony/web";
private ForumApi mForumApi;
public ForumService(){
RequestInterceptor requestInterceptor = new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addHeader("Accept", "application/json");
}
};
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(FORUM_SERVER_URL)
.setRequestInterceptor(requestInterceptor)
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
mForumApi = restAdapter.create(ForumApi.class);
}
public ForumApi getmForumApi() {
return mForumApi;
}
public interface ForumApi{
@GET("/video/lasts_videos")
public Observable<List<Data>> getVideos();
/*@GET("/posts/{id}")
public Observable<Post>
getPost(@Path("id") int postId);
@GET("/comments")
public Observable<List<Comment>>
getComments(@Query("postId") int postId);
@POST("/posts")
public Observable<Post> postPost(Post post);*/
}
}
public class ListPresenter {
ListActivity mView;
ForumService mForum;
public ListPresenter(ListActivity mView, ForumService mForum) {
this.mView = mView;
this.mForum = mForum;
}
public void loadPosts() {
mForum.getmForumApi()
.getVideos()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<List<Data>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(List<Data> posts) {
mView.displayPosts(posts);
}
});
}
}
And then, I execute the method loadPosts()
from my activity, to fill a list and display in a ListView.
If i look about android logs, I can see how retrofit displays to me that found the results, but for any reason onNext is never called.
Upvotes: 1
Views: 1450
Reputation: 13321
From the discussion in the comments:
onNext
wan't been called because there was a problem in the JSON deserialization. onError
was called instead.
Upvotes: 1