Okhttp: FATAL EXCEPTION: OkHttp Dispatcher

Created on 31 May 2016  Â·  1Comment  Â·  Source: square/okhttp

I'm having a trouble, use a Google search, but did not find a solution:

compile 'com.squareup.okhttp3:okhttp:3.3.1'
Tested devices: XiaoMi Redmi Note3 with Android 5.0.2

line

25     @Override
26    public List<SpaceCategory> obtainSpaceCategory(final String url) {
27        String url2 = "http://192.168.6.248/MVPDemo/Home/Space/space";
28        OkHttpClient okHttpClient = new OkHttpClient();
29        Request request = new Request.Builder().url(url2).build();
30        Call call = okHttpClient.newCall(request);
31       call.enqueue(new Callback() {
32            @Override
33           public void onFailure(Call call, IOException e) {
34           }
35
36            @Override
37           public void onResponse(Call call, Response response) throws IOException {
38              Log.d("MainImpl","response : " + response.body().string());
39                String result = response.body().string();
40            }
41        });
42
43       return spaceCategories;
44    }



05-31 16:41:25.427 30193-30452/com.passershowe.mvpdemo E/AndroidRuntime:
 FATAL EXCEPTION: OkHttp Dispatcher
                Process: com.passershowe.mvpdemo, PID: 30193
                java.lang.IllegalStateException: closed
                        at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:378)
                        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.passershowe.mvpdemo.model.main.MainImpl$1.onResponse(MainImpl.java:39)
                        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
                        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:818)



Most helpful comment

It's an error to call ResponseBody.string() multiple times. The documentation explains why.

>All comments

It's an error to call ResponseBody.string() multiple times. The documentation explains why.

Was this page helpful?
0 / 5 - 0 ratings