【发布时间】:2019-04-15 18:53:02
【问题描述】:
根据帖子类型,我需要将项目推送到可观察列表。因此,如果不使用 if 闭包(例如 post.type != SomeType),我的可观察列表为空。
所以由于我一直从Single.zip接收NoSuchElementException
这是我的示例代码
val observableList = mutableListOf<Single<Response>>()
if (post.type == SomeType) {
observableList.add(addNewObservable()) <-- adding API call to the lsit
}
return Single.zip(observableList) { arg -> arg } <-- Throws error NoSuchElementException
我想我可以使用post type != SomeType:
observableList.add(Single.just(Response(""))
这会很好用。
那么有没有更好的解决方案呢?我怎样才能避免这个错误?
【问题讨论】:
标签: java android kotlin rx-java rx-java2