- ::47.470 -/com.tongyan.tutelage W/System.err: com.android.volley.NoConnectionError: java.io.InterruptedIOException
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: Caused by: java.io.InterruptedIOException
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okio.Deadline.throwIfReached(Deadline.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okio.Okio$.write(Okio.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okio.RealBufferedSink.flush(RealBufferedSink.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okhttp.internal.http.HttpConnection.flush(HttpConnection.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okhttp.internal.http.HttpTransport.flushRequest(HttpTransport.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:)
- ::47.470 -/com.tongyan.tutelage W/System.err: ... more
这个错误是你在不经意间导致的,或者是没有很好的去熟悉volley包的api导致的。
public void onRequest(String url){
if(isIntnetConn){
StringRequest request = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
mListener.onSuccess(s);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
String errorMsg = "";
if(volleyError instanceof TimeoutError) {
mListener.onError();
} else if(volleyError instanceof ServerError) {
mListener.onError();
} else {
mListener.onError();
errorMsg = mContext.getResources().getString(R.string.request_error);
}
}
});
request.setRetryPolicy(new DefaultRetryPolicy( * , , 1.0f));//设置超时时间
mQueue.add(request);
//mQueue.start();
}else{
Toast.makeText(mContext, "当前的网络连接不可用", Toast.LENGTH_SHORT).show();
mListener.onIntnetDisConn();
}
}
只是因为加了下面这句,bug如期而至。
//mQueue.start();
其实,在RequestQueue实例化的时候,就已经有start了。
private RequestQueue mQueue;
private Context mContext; public HttpServiceUtils(HttpResquestListener listener,Context context){
mListener = listener;
mContext = context;
mQueue = Volley.newRequestQueue(context);
}
public class Volley {
private static final String DEFAULT_CACHE_DIR = "volley"; public Volley() {
} public static RequestQueue newRequestQueue(Context context, HttpStack stack) {
File cacheDir = new File(context.getCacheDir(), "volley");
String userAgent = "volley/0"; try {
String network = context.getPackageName();
PackageInfo queue = context.getPackageManager().getPackageInfo(network, );
userAgent = network + "/" + queue.versionCode;
} catch (NameNotFoundException var6) {
;
} if(stack == null) {
if(VERSION.SDK_INT >= ) {
stack = new HurlStack();
} else {
stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
}
} BasicNetwork network1 = new BasicNetwork((HttpStack)stack);
RequestQueue queue1 = new RequestQueue(new DiskBasedCache(cacheDir), network1);
queue1.start();
return queue1;
} public static RequestQueue newRequestQueue(Context context) {
return newRequestQueue(context, (HttpStack)null);
}
}
queue1.start(); 已经在实例化RequestQueue的时候,就被调用了。
https://*.com/questions/31158858/random-com-android-volley-noconnection-error-java-io-interruptedioexception-st/31181611#31181611