您的位置:首页 > 编程语言 > Java开发

java.lang.IllegalStateException: closed when trying to access response in onResponse(Response respo

2016-09-13 17:49 621 查看
在使用okhttp成功接收json数据后进行打印log:

@Override

public void onResponse(Response response) throws IOException {

// Log.i(“log”, ” onResponse() reuslt=” + response.body().string());

JSONObject jsonobject =JSON.parseObject(response.body().string());

Log.d(“log”,”数据成功 码:”+jsonobject.get(“code”));

}

错误原因:由于某处两次都调用了response.body().string();

导致closed,有且只能调用一次

错:

09-13 17:41:22.763 19725-21188/mhwh.wow E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher

Process: mhwh.wow, PID: 19725

java.lang.IllegalStateException: closed

at com.squareup.okhttp.internal.http.HttpConnectionFixedLengthSource.read(HttpConnection.java:454)atokio.Buffer.writeAll(Buffer.java:574)atokio.RealBufferedSource.readByteArray(RealBufferedSource.java:87)atcom.squareup.okhttp.ResponseBody.bytes(ResponseBody.java:56)atcom.squareup.okhttp.ResponseBody.string(ResponseBody.java:82)atmhwh.wow.fragment.FragmentThreeTimeRecord1.onResponse(FragmentThreeTimeRecord.java:149)

at com.squareup.okhttp.CallAsyncCall.execute(Call.java:150)atcom.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)atjava.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:587)

at java.lang.Thread.run(Thread.java:841)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐