2016-02-09 75 views
0

我在生產版本(市場構建版)中發生此故障。所以很多用戶都會遇到這個崩潰,但我無法重現它。重試獲取數據:rx.exceptions.MissingBackpressureException

這是堆棧跟蹤:

Fatal Exception: java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling. 
    at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:60) 
    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:5832) 
    at java.lang.reflect.Method.invoke(Method.java) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 

Caused by rx.exceptions.OnErrorNotImplementedException 
    at rx.Observable$31.onError(Observable.java:7280) 
    at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:154) 
    at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111) 
    at rx.observers.SerializedObserver.onError(SerializedObserver.java:122) 
    at rx.observers.SerializedSubscriber.onError(SerializedSubscriber.java:79) 
    at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69) 
    at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:183) 
    at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:159) 
    at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) 
    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:5832) 
    at java.lang.reflect.Method.invoke(Method.java) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 

Caused by rx.exceptions.MissingBackpressureException 
    at rx.internal.util.RxRingBuffer.onNext(RxRingBuffer.java:349) 
    at rx.internal.operators.OperatorZip$Zip$InnerSubscriber.onNext(OperatorZip.java:330) 
    at rx.subjects.SubjectSubscriptionManager$SubjectObserver.onNext(SubjectSubscriptionManager.java:224) 
    at rx.subjects.PublishSubject.onNext(PublishSubject.java:114) 
    at com.opensooq.OpenSooq.ui.BaseActivity$2.onClick(BaseActivity.java:562) 
    at android.view.View.performClick(View.java:5156) 
    at android.view.View$PerformClick.run(View.java:20755) 
    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:5832) 
    at java.lang.reflect.Method.invoke(Method.java) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 

這是我的代碼:

public static final Func1 RETRY_CONDITION = new Func1<Observable<? extends Throwable>, Observable<?>>() { 
    @Override 
    public Observable<?> call(Observable<? extends Throwable> observable) { 
     return observable.zipWith(NO_INTERENT_CLICKED_EVENT, new Func2<Throwable, Object, Object>() { 
      @Override 
      public Object call(Throwable throwable, Object o) { 
       return throwable; 
      } 
     }); 
    } 
}; 

public static final PublishSubject<Object> NO_INTERENT_CLICKED_EVENT = PublishSubject.create(); 

noInternetView.findViewById(R.id.bRetry).setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        noInternetView.findViewById(R.id.noInternetLoading).setVisibility(View.VISIBLE); 
        noInternetView.findViewById(R.id.llBody).setVisibility(View.GONE); 
        NO_INTERENT_CLICKED_EVENT.onNext(new Object()); 
       } 
      });  

調用登錄觀察到:

bindLifecycle(loginObservable 
      .observeOn(AndroidSchedulers.mainThread()) 
      .doOnError(new Action1<Throwable>() { 
       @Override 
       public void call(Throwable throwable) { 
        if (throwable instanceof RetrofitError) { 
         toggleNoInternetView(true); 
        } 
        hideLoader(); 
       } 
      }) 
      .doOnNext(new Action1<LoginResult>() { 
       @Override 
       public void call(LoginResult loginResult) { 
       // Handle success 
       } 
      }) 
      .doOnCompleted(new Action0() { 
       @Override 
       public void call() { 
        hideLoader(); 
        toggleNoInternetView(false); 
       } 
      }) 
      .retryWhen(BaseActivity.RETRY_CONDITION), LifecycleEvent.DESTROY) 
      .subscribe(); 

我的代碼重試獲取數據時,網絡連接有已丟失。

請任何幫助來解決這個問題。

+0

您需要在'subscribe()'方法中添加一些內容,可能是Subscriber或任何錯誤處理程序,哪些錯誤會拋出。 –

回答

2

有兩個故障需要考慮。第一個是OnErrorNotImplementedException,這意味着您使用subscribe(Action1)而不是subscribe(Action1, Action1),並且該例外無法到達任何地方。

第二個故障是zip中的緩衝區溢出,可能是因爲您的輸入上沒有使用onBackpressureBufferonBackpressureDrop。由於你的例子沒有zip,所以我不能說爲什麼它不能使用click事件。也許拉鍊的其他來源或壓縮的下降速度較慢。也許你會把事件推到NO_INTERENT_CLICKED_EVENT其他地方。

+0

感謝您的重播,我很抱歉遲到, 我更新了我的問題,請檢查一遍 –

+0

只要使用'NO_INTERENT_CLICKED_EVENT.onBackpressureBuffer()' – akarnokd

+0

謝謝你,我會嘗試這種解決方案, 但是你能告訴我我如何重現我? –