我得到了一个非常奇怪的索引超出范围异常,这与我收到的任何其他异常不同。它说索引是 16 并且大小是 17 并且仍然崩溃?这是它崩溃的代码:
public void subscribe(@io.reactivex.annotations.NonNull ObservableEmitter<Pair> observableEmitter) throws Exception {
for (int i = 0; i < messages.size(); i++) {
MessageInterface mi = messages.get(i);
if (mi != null
&& (mi.getMsgTimestamp() <= message.getMsgTimestamp()
|| (mi.getMsgTimestamp() < message.getMsgTimestamp() && mi.getUsec() == message.getUsec()))) {
...
}
observableEmitter.onComplete();
}
在这一行崩溃: MessageInterface mi = messages.get(i);
知道该怎么做吗?我以前从未见过这样的事情。
崩溃日志的副本:
FATAL EXCEPTION: main
Process: com.app.debug, PID: 15675
io.reactivex.exceptions.OnErrorNotImplementedException: Index: 16, Size: 17
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
at io.reactivex.internal.observers.LambdaObserver.onError(LambdaObserver.java:74)
at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.checkTerminated(ObservableObserveOn.java:276)
at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:192)
at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IndexOutOfBoundsException: Index: 16, Size: 17
at java.util.ArrayList.get(ArrayList.java:411)
at com.app.MessageList$8.subscribe(MessageList.java:282)
at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
at io.reactivex.Observable.subscribe(Observable.java:10842)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)