Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RxJava中的Zip操作员未使用改装_Java_Android_Observable_Retrofit2_Rx Java2 - Fatal编程技术网

RxJava中的Zip操作员未使用改装

RxJava中的Zip操作员未使用改装,java,android,observable,retrofit2,rx-java2,Java,Android,Observable,Retrofit2,Rx Java2,我试图在android的RxJava中使用zip操作符,我试图执行3个并行API调用,以将结果汇总在一起。但我的zip操作符并没有产生结果。我的示例问题的代码如下所示: 我的gradle文件的代码 compile 'com.squareup.retrofit2:retrofit:2.0.2' compile 'com.squareup.retrofit2:converter-gson:2.0.2' compile 'com.squareup.retrofit2:adapter-rxjava:2.

我试图在android的RxJava中使用zip操作符,我试图执行3个并行API调用,以将结果汇总在一起。但我的zip操作符并没有产生结果。我的示例问题的代码如下所示:

我的gradle文件的代码

compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
exclude 'META-INF/rxjava.properties'
我还将此包含在我的gradle文件中

compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
exclude 'META-INF/rxjava.properties'
我的改装客户端的代码

retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
    .addConverterFactory(GsonConverterFactory.create())
    .client(client).build();
我的API接口的代码

public interface ApiInterface {
    @GET("/users/{UUID}/count.json")
    Observable<Count> getCountInfo(@Path("UUID") String UUID, @Query("store_id") String sort);
    @GET("v1/users/{UUID}.json")
    Observable<GetStatus> getState(@Path("UUID") String UUID);
    @GET("v1/user/{UUID}/points.json")
    Observable<Response> getResponse(@Path("UUID") String UUID);
}
公共接口{
@获取(“/users/{UUID}/count.json”)
可观察的getCountInfo(@Path(“UUID”)字符串UUID,@Query(“store_id”)字符串排序);
@获取(“v1/users/{UUID}.json”)
可观察的getState(@Path(“UUID”)字符串UUID);
@获取(“v1/user/{UUID}/points.json”)
可观察的getResponse(@Path(“UUID”)字符串UUID);
}
我的观测值的代码是

Retrofit repo = APIClient.getClient(baseUrl);
Observable<Count> userObservable = repo.create(ApiInterface.class)
    .getCount(userid,"1")
    .subscribeOn(Schedulers.newThread())
    .observeOn(Schedulers.io());
Observable<GetStatus> eventObservable = APIClient.getClient(baseUrl)
    .create(ApiInterface.class)
    .getState(userid)
    .subscribeOn(Schedulers.newThread())
    .observeOn(Schedulers.io());
Observable<Response> eventsObservable1 = APIClient
    .getClient(baseUrl)
    .create(ApiInterface.class)
    .getPoints(userid)
    .subscribeOn(Schedulers.newThread())
    .observeOn(Schedulers.io());
reformation repo=APIClient.getClient(baseUrl);
Observable userObservable=repo.create(ApiInterface.class)
.getCount(用户ID,“1”)
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io());
Observable eventObservable=APIClient.getClient(baseUrl)
.create(apinterface.class)
.getState(用户ID)
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io());
可观测事件Sobservable1=APIClient
.getClient(baseUrl)
.create(apinterface.class)
.getPoints(用户ID)
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io());
我的组合observable和zip运算符的代码为:

Observable<CommonSplashResponse> combined = Observable.zip(userObservable, eventsObservable, eventsObservable1,
new Func3<Count, GetStatus, Response, CommonResponse>() {
    @Override
    public CommonResponse call(Count count, GetStatus uStatus, 
        Response lResponse) {
        return new CommonResponse(count, uStatus, lResponse);
    }
});
combined.subscribe(new Subscriber<CommonSplashResponse>() {
    @Override
    public void onCompleted() {
    }
    @Override
    public void onError(Throwable e) {
    }
    @Override
    public void onNext(CommonResponse o) {
        LOG.info("Count Value is " + o.getCount());
        /**
        ***
        */
    }
});
Observable combined=Observable.zip(userObservable、eventsObservable、eventsObservable1、,
新功能3(){
@凌驾
公共CommonResponse调用(计数、GetStatus uStatus、,
回应(回应){
返回新的CommonResponse(计数、uStatus、lResponse);
}
});
组合。订阅(新订阅方(){
@凌驾
未完成的公共无效(){
}
@凌驾
公共无效申报人(可丢弃的e){
}
@凌驾
public void onNext(CommonResponse o){
LOG.info(“计数值为”+o.getCount());
/**
***
*/
}
});
我面临的问题是,组合可观察对象onNext中的语句没有被执行。 执行中出现问题的原因可能是什么? 所以我想问:

  • 我的依赖项中有任何问题吗
  • 是否应该使用AndroidSchedulers.mainThread()而不是Schedulers.io()呢
  • 要使.zip()操作符发出任何内容,所有压缩的可观察对象必须至少发出一次。如果您的一个观察对象发出错误,或者根本不发出,您将永远不会收到onNext事件

    • 要检查错误排放,请在subscribe中向OneError中添加日志记录或断点
    • 为了检查丢失的发射,您可以在所有压缩的观测值之后添加doOnNext和doOnCompleted调用并记录,然后查看哪一个不发射

    干杯

    看起来您的一个(或多个)改装观测要么发出错误,要么根本不发出任何东西。您可能想在
    onError
    onCompleted
    中添加一些日志记录。是的,我尝试过这样做,URL的格式出现了一些问题,因此引发了404异常。我调试并发现了这个问题。谢谢你的帮助!