2016-07-26 186 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

这很好,其实我几天前有同样的例外,我解决了它的方式,我在回答中提到。所以我认为这对你也有帮助。 –