0
我正在使用RxJava,除了在引發這些錯誤的情況下,一切看起來都不錯。RxJava序列不包含元素錯誤
Caused by: java.util.NoSuchElementException: Sequence contains no elements
at rx.internal.operators.OperatorSingle$ParentSubscriber.onCompleted(OperatorSingle.java:118)
at rx.internal.operators.OperatorTake$1.onCompleted(OperatorTake.java:56)
at rx.internal.operators.OnSubscribeFilter$FilterSubscriber.onCompleted(OnSubscribeFilter.java:99)
at rx.internal.operators.OnSubscribeFromIterable$IterableProducer.slowpath(OnSubscribeFromIterable.java:134)
at rx.internal.operators.OnSubscribeFromIterable$IterableProducer.request(OnSubscribeFromIterable.java:89)
at rx.internal.operators.OperatorTake$1$1.request(OperatorTake.java:109)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OperatorTake$1.setProducer(OperatorTake.java:93)
at rx.internal.operators.OnSubscribeFilter$FilterSubscriber.setProducer(OnSubscribeFilter.java:104)
at rx.internal.operators.OnSubscribeFromIterable.call(OnSubscribeFromIterable.java:63)
at rx.internal.operators.OnSubscribeFromIterable.call(OnSubscribeFromIterable.java:34)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OnSubscribeFilter.call(OnSubscribeFilter.java:45)
at rx.internal.operators.OnSubscribeFilter.call(OnSubscribeFilter.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:250)
at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:147)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
at rx.internal.operators.OperatorMerge$MergeSubscriber.emitScalar(OperatorMerge.java:399)
at rx.internal.operators.OperatorMerge$MergeSubscriber.tryEmit(OperatorMerge.java:357)
at rx.internal.operators.OperatorMerge$InnerSubscriber.onNext(OperatorMerge.java:852)
at rx.internal.operato
編輯: 的問題是在功能NumberObservables::mergeNumberAndName
,
public static Observable<Trailer> mergeTrailerType(Trailer trailer) {
String id = number.getId();
return Observable.from(Store.names())
.first(name -> id.equals(name.getId()))
.map(name -> {
number.setName(name);
return number;
});
}
,我可以看到first
使得問題,但我不能與採取更換(1)或firstOrDefault(找不到getId()
)。它可以與single
一起使用嗎?你可能在流(NumberObservables::getByNumber
或NumberObservables::mergeNumberAndName
)的single()
操作某處申請
是的,我發現它現在,我在'NumberObservables :: mergeNumberAndName'中應用'.first'操作符,這就是爲什麼它會拋出異常。你知道我該如何解決它? – Claire
好吧,很難說不理解你的邏輯,你可以使用'firstOrDefault'來提供默認值,但是通常你想從Observable中獲得單個項目,而不是這樣,所以你的邏輯要根據你期望的來完善在這種情況下發出 – yosriz
我用函數NumberObservables :: mergeNumberAndName和其他細節改變了這個問題。你可以看到。 – Claire