Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FATAL EXCEPTION: OkHttp Dispatcher #2593

Closed
PassersHowe opened this issue May 31, 2016 · 1 comment
Closed

FATAL EXCEPTION: OkHttp Dispatcher #2593

PassersHowe opened this issue May 31, 2016 · 1 comment

Comments

@PassersHowe
Copy link

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)

@swankjesse
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants