2016-07-26 359 views
0

我在使用改進進行網絡調用時發生崩潰。這是我的堆棧跟蹤。致命異常:java.lang.IllegalStateException:致命異常在Scheduler.Worker線程上拋出

Fatal Exception: java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread. 
     at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:62) 
     at android.os.Handler.handleCallback(Handler.java:733) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5584) 
     at java.lang.reflect.Method.invokeNative(Method.java) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
     at dalvik.system.NativeStart.main(NativeStart.java) 
Caused by rx.b.i: Error occurred when trying to propagate error to Observer.onError 
     at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:2192) 
     at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) 
     at rx.observers.SerializedObserver.onError(SerializedObserver.java:158) 
     at rx.observers.SerializedSubscriber.onError(SerializedSubscriber.java:79) 
     at rx.internal.operators.OperatorTakeUntil$1.onError(OperatorTakeUntil.java:49) 
     at rx.internal.operators.OperatorToObservableList$1.onError(OperatorToObservableList.java:99) 
     at rx.internal.operators.OperatorFilter$1.onError(OperatorFilter.java:47) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:243) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:779) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:540) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:529) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.onError(OperatorMerge.java:253) 
     at rx.internal.operators.OperatorMap$1.onError(OperatorMap.java:48) 
     at rx.internal.operators.OnSubscribeRedo$4$1.onError(OnSubscribeRedo.java:331) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:243) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:779) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:540) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:529) 
     at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:813) 
     at rx.Observable$ThrowObservable$1.call(Observable.java:11200) 
     at rx.Observable.unsafeSubscribe(Observable.java:8314) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:7235) 
     at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54) 
     at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54) 
     at rx.internal.operators.OnSubscribeRedo$3$1.onNext(OnSubscribeRedo.java:1307) 
     at rx.internal.operators.NotificationLite.accept(NotificationLite.java:150) 
     at rx.subjects.SubjectSubscriptionManager$SubjectObserver.emitNext$a2d69e2(SubjectSubscriptionManager.java:253) 
     at rx.subjects.BehaviorSubject.onNext(BehaviorSubject.java:160) 
     at rx.internal.operators.OnSubscribeRedo$2$1.onError(OnSubscribeRedo.java:242) 
     at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:254) 
     at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:186) 
     at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) 
     at android.os.Handler.handleCallback(Handler.java:733) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5584) 
     at java.lang.reflect.Method.invokeNative(Method.java) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
     at dalvik.system.NativeStart.main(NativeStart.java) 
Caused by rx.b.a: 2 exceptions occurred. 
     at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:2192) 
     at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) 
     at rx.observers.SerializedObserver.onError(SerializedObserver.java:158) 
     at rx.observers.SerializedSubscriber.onError(SerializedSubscriber.java:79) 
     at rx.internal.operators.OperatorTakeUntil$1.onError(OperatorTakeUntil.java:49) 
     at rx.internal.operators.OperatorToObservableList$1.onError(OperatorToObservableList.java:99) 
     at rx.internal.operators.OperatorFilter$1.onError(OperatorFilter.java:47) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:243) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:779) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:540) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:529) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.onError(OperatorMerge.java:253) 
     at rx.internal.operators.OperatorMap$1.onError(OperatorMap.java:48) 
     at rx.internal.operators.OnSubscribeRedo$4$1.onError(OnSubscribeRedo.java:331) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:243) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:779) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:540) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:529) 
     at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:813) 
     at rx.Observable$ThrowObservable$1.call(Observable.java:11200) 
     at rx.Observable.unsafeSubscribe(Observable.java:8314) 
     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:7235) 
     at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54) 
     at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54) 
     at rx.internal.operators.OnSubscribeRedo$3$1.onNext(OnSubscribeRedo.java:1307) 
     at rx.internal.operators.NotificationLite.accept(NotificationLite.java:150) 
     at rx.subjects.SubjectSubscriptionManager$SubjectObserver.emitNext$a2d69e2(SubjectSubscriptionManager.java:253) 
     at rx.subjects.BehaviorSubject.onNext(BehaviorSubject.java:160) 
     at rx.internal.operators.OnSubscribeRedo$2$1.onError(OnSubscribeRedo.java:242) 
     at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:254) 
     at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:186) 
     at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) 
     at android.os.Handler.handleCallback(Handler.java:733) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5584) 
     at java.lang.reflect.Method.invokeNative(Method.java) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
     at dalvik.system.NativeStart.main(NativeStart.java) 
Caused by rx.b.b: Chain of Causes for CompositeException In Order Received => 
     at com.crashlytics.android.core.SessionProtobufHelper.getEventAppExecutionExceptionSize(SessionProtobufHelper.java:619) 
     at com.crashlytics.android.core.SessionProtobufHelper.getEventAppExecutionExceptionSize(SessionProtobufHelper.java:622) 
     at com.crashlytics.android.core.SessionProtobufHelper.getEventAppExecutionExceptionSize(SessionProtobufHelper.java:622) 
     at com.crashlytics.android.core.SessionProtobufHelper.getEventAppExecutionSize$322e56cf(SessionProtobufHelper.java:554) 
     at com.crashlytics.android.core.SessionProtobufHelper.getEventAppSize$565823c3(SessionProtobufHelper.java:510) 
     at com.crashlytics.android.core.SessionProtobufHelper.getSessionEventSize(SessionProtobufHelper.java:2482) 
     at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.writeSessionEvent$13f1f7ff(CrashlyticsUncaughtExceptionHandler.java:1052) 
     at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.writeFatal(CrashlyticsUncaughtExceptionHandler.java:23766) 
     at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler$5.call(CrashlyticsUncaughtExceptionHandler.java:1238) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at io.fabric.sdk.android.services.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:75) 
     at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:30) 
     at java.lang.Thread.run(Thread.java:841) 
Caused by retrofit.RetrofitError 
     at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395) 
     at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240) 
     at $Proxy4.getChartStockData(Unknown Source) 
     at com.talkoot.android.web.GoogleFinanceManager.access$lambda$0(GoogleFinanceManager.java:1082) 
     at com.talkoot.android.web.GoogleFinanceManager$$Lambda$1.call(Unknown Source) 
     at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:1032) 
     at rx.Observable$2.call(Observable.java:1162) 
     at rx.Observable.unsafeSubscribe(Observable.java:8314) 
     at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94) 
     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:841) 
Caused by java.net.SocketTimeoutException 
     at java.net.PlainSocketImpl.read(PlainSocketImpl.java:491) 
     at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46) 
     at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240) 
     at java.io.InputStream.read(InputStream.java:162) 
     at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142) 
     at java.io.BufferedInputStream.read(BufferedInputStream.java:227) 
     at com.android.okhttp.internal.Util.readAsciiLine(Util.java:316) 
     at com.android.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:308) 
     at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:135) 
     at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:644) 
     at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347) 
     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296) 
     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503) 
     at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73) 
     at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38) 
     at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326) 
     at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240) 
     at $Proxy4.getChartStockData(Unknown Source) 
     at com.talkoot.android.web.GoogleFinanceManager.access$lambda$0(GoogleFinanceManager.java:1082) 
     at com.talkoot.android.web.GoogleFinanceManager$$Lambda$1.call(Unknown Source) 
     at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:1032) 
     at rx.Observable$2.call(Observable.java:1162) 
     at rx.Observable.unsafeSubscribe(Observable.java:8314) 
     at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94) 
     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:841) 

這是我的代碼。

public void downloadChartFullData(@NonNull String ticker, @NonNull String exchange, @NonNull ChartTimePeriod chartTimePeriod, 
             @NonNull ChartFragment fragment) { 
     if (!ConnectionUtils.isNetworkConnected(false)) 
      return; 
     Log.v(TAG + Utils.getCurrentThreadInfo(), "handleActionDownloadChartStockData"); 
     getChartStockData(ticker, exchange) 
       .compose(fragment.bindToLifecycle()) 
       .subscribeOn(Schedulers.io()) 
       .observeOn(AndroidSchedulers.mainThread()) 
       .retryWhen(RetryWithDelay.newInstance()) 
       .flatMap(new Func1<List<ChartDataEntity>, Observable<ChartDataEntity>>() { 
        @Override 
        public Observable<ChartDataEntity> call(List<ChartDataEntity> stockEntities) { 
         return Observable.from(stockEntities); 
        } 
       }) 
       .filter(new Func1<ChartDataEntity, Boolean>() { 
        @Override 
        public Boolean call(ChartDataEntity ChartDataEntity) { 
         return ChartDataEntity.getDate() != null; // to filter out data without Date. 
        } 
       }) 
       .toList() 
       .compose(fragment.bindToLifecycle()) 
       .doOnNext(new Action1<List<ChartDataEntity>>() { 
        @Override 
        public void call(List<ChartDataEntity> stockEntities) { 
         mBus.post(new OnChartDataReceivedEvent(TAG, stockEntities, ticker, exchange, 
           chartTimePeriod)); 
        } 
       }) 
       .subscribe(new Action1<List<ChartDataEntity>>() { 
        @Override 
        public void call(List<ChartDataEntity> stockEntities) { 
        } 
       }, new Action1<Throwable>() { 
        @Override 
        public void call(Throwable throwable) { 
         Log.e("TAG", throwable.getMessage()); 
        } 
       }); 
    } 

public Observable<List<ChartDataEntity>> getChartStockData(@NonNull String ticker, @NonNull String exchange) { 
     return Observable.fromCallable(() -> { 
      Log.i(TAG + Utils.getCurrentThreadInfo(), "Getting stockChart"); 
      Response response = mGoogleFinanceWebInterface.getChartStockData(ticker, exchange, 
        GoogleFinanceWebInterface.INTERVAL_DEFAULT, GoogleFinanceWebInterface.PERIOD_DEFAULT, 
        new GoogleFinanceWebInterface.ChartParameters()); 
      String strResponse = responseMapper.call(response); 
      return StockUtils.convertResponseToChartData(strResponse); 
     }); 
    } 

任何幫助,將不勝感激。

+0

加入這一行

.observeOn(AndroidSchedulers.mainThread()) 

,你都可以從你的連接超時異常。測試郵遞員的API調用,看看它是否工作 – SoroushA

+0

是的我知道我得到一個超時異常。我想在我的Rx代碼中處理這個問題。我期待訂閱方法的throwable調用中的每個錯誤。但爲什麼這個人會崩潰,而不是去訂閱可拋出的電話。 – WonderKid

+0

你確定你在RestAdapter.java:395上調用onError嗎? – SoroushA

回答

0

好像你需要開始mainThread之前第二組成運營商是因爲改造相關的執行應該是相同的線程。

所以剛過toList()

+0

我實際上已經解決了它在onErrorReturn回調中處理異常。我無法在onError中執行它,因爲它是一個compositeException,我認爲最近在RxJava中解決了這個問題,但是尚未包含在RxAndroid中。謝謝您的回答。但在我的情況下,改裝電話是在後臺處理的,它的工作非常完美。當我們需要處理的互聯網/服務器出現問題時會引發異常。謝謝。 – WonderKid

+0

這很好,其實我幾天前有同樣的例外,我解決了它的方式,我在回答中提到。所以我認爲這對你也有幫助。 –