天天看點

okhttp3: java.lang.IllegalStateException: closed

苦惱了一天,看了這篇文章https://blog.csdn.net/ucxiii/article/details/52447945終于找到問題所在了,感謝部落客。,04-06 20:26:55.461 7632-7675/com.littlegold.littlegoldweather E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher

                                                                                Process: com.littlegold.littlegoldweather, PID: 7632

                                                                                java.lang.IllegalStateException: closed

                                                                                    at okhttp3.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:414)

                                                                                    at okio.Buffer.writeAll(Buffer.java:993)

                                                                                    at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:106)

                                                                                    at okhttp3.ResponseBody.bytes(ResponseBody.java:128)

                                                                                    at okhttp3.ResponseBody.string(ResponseBody.java:154)

                                                                                    at com.littlegold.littlegoldweather.fragment.ProvinceFragment$2.onResponse(ProvinceFragment.java:90)

                                                                                    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:126)

                                                                                    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)

                                                                                    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) 使用okhttp3的時候遇到這個問題,原因是使用了兩次response.body().string(),解決方法自然是隻用一次就可以了。