EOFException排球错误

时间:2016-03-04 22:55:33

标签: android android-studio android-volley

我之前询问过这个问题(Volley.NoConnectionError : java.io.EOFException 0),但没有回答。

我有完全相同的问题。它运行良好,只是某个时候...主要是当我第一次运行EOFException时运行它。

这是我的Volley请求(忽略不良格式化):

 public void makeJsonObjectRequest() {
    Log.e("TMS", "makeJsonObjectRequest 111 ");
    final CountDownLatch cdl = new CountDownLatch(1);

    JsonArrayRequest req = new JsonArrayRequest(urlJsonArry,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {                       
                    Log.d("TMS", "aaaaaa " +  response.toString());

                    try {

                        jsonResponse = "";
                        String id = null;
                        String naslov = null;
                        String akter = null;
                        String akter_id = null;
                        String slika = null;
                        String izjava = null;
                        String izvor = null;
                        String datum_izjave = null;
                        String tip_ocena = null;
                        String kategorija = null;
                        String status = null;
                        String komentar_istinomera = null;
                        String tagovi = null;

                        for (int i = 0; i < response.length(); i++) {
                            NewsItem newsItem = new NewsItem();
                            JSONObject person = (JSONObject) response.get(i);
                            // Parsing json object response response will be a json object
                            id = person.getString("id");
                            naslov = person.getString("naslov");
                            akter = person.getString("akter");
                            akter_id = person.getString("akter_id");
                            slika = person.getString("slika");
                            izjava = person.getString("izjava");
                            izvor = person.getString("izvor");
                            datum_izjave = person.getString("datum_izjave");
                            tip_ocena = person.getString("tip_ocena");
                            kategorija = person.getString("kategorija");
                            status = person.getString("status");
                            komentar_istinomera = person.getString("komentar_istinomera");
                            tagovi = person.getString("tagovi");

                            jsonResponse += "id: " + id + "\n\n";
                            jsonResponse += "naslov: " + naslov + "\n\n";
                            jsonResponse += "akter: " + akter + "\n\n";
                            jsonResponse += "akter_id: " + akter_id + "\n\n";
                            jsonResponse += "slika: " + slika + "\n\n";
                            jsonResponse += "izjava: " + izjava + "\n\n";
                            jsonResponse += "izvor: " + izvor + "\n\n";
                            jsonResponse += "datum_izjave: " + datum_izjave + "\n\n";
                            jsonResponse += "tip_ocena: " + tip_ocena + "\n\n";
                            jsonResponse += "kategorija: " + kategorija + "\n\n";
                            jsonResponse += "status: " + status + "\n\n";
                            jsonResponse += "komentar: " + komentar_istinomera + "\n\n";
                            jsonResponse += "tagovi: " + tagovi + "\n\n";
                           /* Log.e(TAG,"JSON IS: " + id);
                            Log.e(TAG,"JSON IS: " + naslov);
                            Log.e(TAG,"JSON IS: " + akter);
                            Log.e(TAG,"JSON IS: " + akter_id);
                            Log.e(TAG,"JSON IS: " + slika);
                            Log.e(TAG,"JSON IS: " + izjava);
                            Log.e(TAG,"JSON IS: " + izvor);
                            Log.e(TAG,"JSON IS: " + datum_izjave);
                            Log.e(TAG,"JSON IS: " + tip_ocena);
                            Log.e(TAG,"JSON IS: " + kategorija);
                            Log.e(TAG,"JSON IS: " + status);
                            Log.e(TAG, "JSON IS: " + komentar);
                            Log.e(TAG, "JSON IS: " + tagovi);*/

                            newsItem.setIds(id);
                            newsItem.setNaslov(naslov);
                            newsItem.setAkter(akter);
                            newsItem.setAkterId(akter_id);
                            newsItem.setSlika(slika);
                            newsItem.setIzjava(izjava);
                            newsItem.setIzvor(izvor);
                            newsItem.setDatum_izjave(datum_izjave);
                            newsItem.setTip_ocena(tip_ocena);
                            newsItem.setKategorija(kategorija);
                            newsItem.setStatus(status);
                            newsItem.setKomentar_istinomera(komentar);
                            newsItem.setTagovi(tagovi);

                            newsItemList.add(newsItem);

                            //int size = newsItemList.size();
                            //Log.d("TMS", "getNaslov: " + newsItem.getNaslov() + " SIZE: " + size);

                            cdl.countDown();
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                        Log.e("TMS", "makeJsonObjectRequest 3333 JSONException");
                    }

                }
            }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            Log.e("TMS", "makeJsonObjectRequest 44444 onErrorResponse" + error.getMessage());
        }
    });

    req.setRetryPolicy(new DefaultRetryPolicy(5000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));


    // Adding request to request queue
    volleyRequest.getInstance().addToRequestQueue(req);

    try {
        cdl.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

错误监听器打印此行:

Log.e("TMS", "makeJsonObjectRequest 44444 onErrorResponse" + error.getMessage());
  

makeJsonObjectRequest 44444 onErrorResponse java.io.EOFException

和凌空错误日志:

  

E / Volley:[154] BasicNetwork.performRequest:http://www的意外响应代码200。

1 个答案:

答案 0 :(得分:0)

由于这种情况仅在极少数情况下发生,因此如果发生此错误,我已编写代码来重新启动应用程序。