天天看点

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(),解决方法自然是只用一次就可以了。