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)
@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)
相关文章推荐
- java.lang.IllegalStateException: closed when trying to access response in onResponse(Response respon
- android java.lang.IllegalStateException: trying to requery an already closed cursor
- android 6.0+ java.lang.IllegalStateException did not call finish() prior to onResume() completing
- java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
- java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation getting while running test project?
- java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead
- Android Xposed框架出现java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation问题
- java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
- java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
- android开发问题:java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected imp
- java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementatio
- Xposed出现 java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
- java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.()V
- java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resol
- Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
- java.lang.IllegalStateException: getOutputStream() has already been called for this response的解决办法
- 异常 java.lang.IllegalArgumentException: Unable to access unsupported property javax.xml.stream.suppor
- 关于 java.lang.IllegaAccessError:Class ref in pre-verified class resoved to unexpected implementation
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
- java.lang.IllegalStateException: Cannot forward after response has been committed