Rxjava消息错误:引起:rx.exceptions.MissingBackpressureException

时间:2017-06-23 09:21:20

标签: android rx-java

在我的android平台程序中,我计划定期处理一些逻辑 ,并在每个逻辑过程之后,更新UI的视图,  所以我使用了Rxjava的功能

  Observable.interval

但在我这样做之后。我收到一些Rxjava的错误消息。 这是完整的日志。

java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add onError handling.
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:57)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
Caused by: rx.exceptions.OnErrorNotImplementedException
at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.a(InternalObservableUtils.java:386)
at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:383)
at rx.internal.util.ActionSubscriber.a(ActionSubscriber.java:44)
at rx.observers.SafeSubscriber.b(SafeSubscriber.java:153)
at rx.observers.SafeSubscriber.a(SafeSubscriber.java:115)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.a(OperatorObserveOn.java:273)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:216)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)

Caused by: rx.exceptions.MissingBackpressureException
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.a(OperatorObserveOn.java:160)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.a(OperatorSubscribeOn.java:74)
at rx.internal.operators.OnSubscribeTimerPeriodically$1.call(OnSubscribeTimerPeriodically.java:52)
at rx.internal.schedulers.SchedulePeriodicHelper$1.call(SchedulePeriodicHelper.java:72)
at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:189)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)

这里是我的使用代码Rxjava

fun startAnimation(): Unit {

        Observable.interval(0, 1, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe { start() }

    }

函数start()是我的逻辑过程

  fun start(): Unit = newCircle()



 private fun newCircle(): Unit {
    val currentTime = System.currentTimeMillis()
    val circle = Circle()
    mCircleList.add(circle)
    invalidate()
    mLastCreateTime = currentTime
}

private inner class Circle {
    var mCreateTime: Long

    init {
        this.mCreateTime = System.currentTimeMillis()
    }

    val alpha: Int
        get() {
            val percent = (System.currentTimeMillis() - mCreateTime) * 1.3f / mDuration
            val aplpa = ((1.0f - mInterpolator!!.getInterpolation(percent)) * 100).toInt()
            return ((1.0f - mInterpolator!!.getInterpolation(percent)) * 90).toInt()
        }

    val currentRadius: Float
        get() {
            val percent = (System.currentTimeMillis() - mCreateTime) * 1.0f / mDuration
            return mInitialRadius + mInterpolator!!.getInterpolation(percent) * (mMaxRadius - mInitialRadius)
        }
}

fun setInterpolator(interpolator: Interpolator) {
    mInterpolator = interpolator
    if (mInterpolator == null) {
        mInterpolator = LinearInterpolator()
    }
}

我的代码 我对这个问题一无所知,有人能帮我理解吗? 谢谢!

0 个答案:

没有答案