Android SocketTimeoutException使应用程序崩溃
当我使用我的应用程序时,我遇到了致命的错误,我将手机设置为飞行模式以模拟没有互联网连接,当我打开带有互联网请求的片段时,我遇到了崩溃。请帮我解决这个问题。我不知道如何以及在何处捕获或处理该异常 谢谢你的建议 代码运行的地方Android SocketTimeoutException使应用程序崩溃,android,retrofit,rx-java,retrofit2,okhttp,Android,Retrofit,Rx Java,Retrofit2,Okhttp,当我使用我的应用程序时,我遇到了致命的错误,我将手机设置为飞行模式以模拟没有互联网连接,当我打开带有互联网请求的片段时,我遇到了崩溃。请帮我解决这个问题。我不知道如何以及在何处捕获或处理该异常 谢谢你的建议 代码运行的地方 override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) sharedSessi
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
sharedSessionDataStorage.cardProvider
.getCardProvider()
.bindToLifecycle(this)
.doFinally { stopProgress() }
.subscribe({
stopProgress()
updateCardAdapter(it)
}, {
stopProgress()
Ln.e(it)
})
}
我的依赖项列表是
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'
错误日志:
W/art: Suspending all threads took: 8.780ms
W/System.err: java.net.SocketTimeoutException: timeout
W/System.err: at okio.Okio$4.newTimeoutException(Okio.java:230)
W/System.err: at okio.AsyncTimeout.exit(AsyncTimeout.java:275)
W/System.err: at okio.AsyncTimeout$2.read(AsyncTimeout.java:243)
W/System.err: at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
W/System.err: at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
W/System.err: at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211)
W/System.err: at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
W/System.err: at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:75)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
W/System.err: at com.ihsanbal.logging.LoggingInterceptor.intercept(LoggingInterceptor.java:56)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
W/System.err: at com.readystatesoftware.chuck.ChuckInterceptor.intercept(ChuckInterceptor.java:172)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
W/System.err: at okhttp3.RealCall.execute(RealCall.java:69)
W/System.err: at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
W/System.err: at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:41)
W/System.err: at io.reactivex.Observable.subscribe(Observable.java:10179)
W/System.err: at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
W/System.err: at io.reactivex.Observable.subscribe(Observable.java:10179)
W/System.err: at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:32)
W/System.err: at io.reactivex.Observable.subscribe(Observable.java:10179)
W/System.err: at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
W/System.err: at io.reactivex.Observable.subscribe(Observable.java:10179)
W/System.err: at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
W/System.err: at io.reactivex.Observable.subscribe(Observable.java:10179)
W/System.err: at io.reactivex.internal.operators.observable.ObservableSubscribeOn$1.run(ObservableSubscribeOn.java:39)
W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err: at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.app.dev.debug, PID: 17950
java.net.SocketTimeoutException: timeout
at okio.Okio$4.newTimeoutException(Okio.java:230)
at okio.AsyncTimeout.exit(AsyncTimeout.java:275)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:243)
at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211)
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:75)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at com.ihsanbal.logging.LoggingInterceptor.intercept(LoggingInterceptor.java:56)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at com.readystatesoftware.chuck.ChuckInterceptor.intercept(ChuckInterceptor.java:172)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
at okhttp3.RealCall.execute(RealCall.java:69)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:41)
at io.reactivex.Observable.subscribe(Observable.java:10179)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
at io.reactivex.Observable.subscribe(Observable.java:10179)
at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:32)
at io.reactivex.Observable.subscribe(Observable.java:10179)
at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
at io.reactivex.Observable.subscribe(Observable.java:10179)
at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
at io.reactivex.Observable.subscribe(Observable.java:10179)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$1.run(ObservableSubscribeOn.java:39)
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)
I/Process: Sending signal. PID: 17950 SIG: 9
刚刚在Rx java>2.0上尝试了这个错误处理程序,看起来这个错误处理程序解决了套接字超时问题 检查这个答案 [1] : 接收文件
刚刚在Rx java>2.0上尝试了这个错误处理程序,看起来这个错误处理程序解决了套接字超时问题 检查这个答案 [1] : 接收文件
在调用api以获取结果的地方发布代码,但这没有用,因为日志不会显示代码中的错误位置,并且在这种情况下不会触发OneError方法:(你能发布完整的代码吗?什么的完整代码?有一个简单的片段,简单的列表适配器,由我发布的请求填充,或者瓶颈可能在哪里?
sharedSessionDataStorage.cardProvider.getCardProvider()的完整代码)
,这可能是理解问题的关键。在调用api以获取结果的地方发布代码,但这没有用,因为日志不会显示我的代码中的错误位置,并且在这种情况下不会触发OneError方法:(你能发布完整的代码吗?什么的完整代码?有一个简单的片段,简单的列表适配器,由我发布的请求填充,或者瓶颈可能在哪里?sharedSessionDataStorage.cardProvider.getCardProvider()的完整代码,这对于理解问题可能至关重要。