[Android Exception 1A] -com.android.volley.NoConnectionError: java.io.InterruptedIOException

來源:互聯網
上載者:User

標籤:

12-24 14:21:47.470 24220-24220/com.tongyan.tutelage W/System.err: com.android.volley.NoConnectionError: java.io.InterruptedIOException12-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.InterruptedIOException12-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

[Android Exception 1A] -com.android.volley.NoConnectionError: java.io.InterruptedIOException

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.