zoukankan      html  css  js  c++  java
  • [Android Exception 1A] -com.android.volley.NoConnectionError: java.io.InterruptedIOException

    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err: com.android.volley.NoConnectionError: java.io.InterruptedIOException
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:125)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err: Caused by: java.io.InterruptedIOException
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okio.Deadline.throwIfReached(Deadline.java:56)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okio.Okio$1.write(Okio.java:67)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okio.RealBufferedSink.flush(RealBufferedSink.java:154)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okhttp.internal.http.HttpConnection.flush(HttpConnection.java:130)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okhttp.internal.http.HttpTransport.flushRequest(HttpTransport.java:73)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:626)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:109)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
    12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err:     ... 1 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(20 * 1000, 0, 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, 0);
                userAgent = network + "/" + queue.versionCode;
            } catch (NameNotFoundException var6) {
                ;
            }
    
            if(stack == null) {
                if(VERSION.SDK_INT >= 9) {
                    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://stackoverflow.com/questions/31158858/random-com-android-volley-noconnection-error-java-io-interruptedioexception-st/31181611#31181611

  • 相关阅读:
    Hibernate的一些操作
    工作心得
    放款流程
    关于C#事件的自我构想和学习
    委托之winForm窗口间传递数据
    C#中string[]数组和list<string>泛型的相互转换 【转】
    关于注册界面中的一些规则设计时要注意
    系统界面设计---风格
    关于系统注册,做卡号重校验
    关于系统设计中的硬件开发
  • 原文地址:https://www.cnblogs.com/royi123/p/5510821.html
Copyright © 2011-2022 走看看