我试图通过改装和rxAndroid从网上获取值,但是onNext没有被调用。 在这里,我的课程:
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);
}
});
}
}
然后,我从我的活动中执行方法loadPosts()
,以填充列表并在ListView中显示。
如果我查看android日志,我可以看到改装如何向我显示找到结果,但由于任何原因onNext永远不会被调用。
答案 0 :(得分:1)
从评论中的讨论:
onError
因为JSON反序列化存在问题而未被调用。 public void moveRectangleTo(int x, int y)
{
box.setLocation(x, y);
repaint();
}
被调用了。