Volley.NoConnectionError:java.io.EOFException 0

时间:2014-11-12 11:33:13

标签: java android request android-volley

我不明白这个错误,虽然我在网上搜索了很多次,但无事可做,错误有时出现。 我做了一个使用VOlley库的应用程序,一切运行良好,95%的请求都有效,但有时我有错误;

11-12 12:18:54.991: I/Error(1870): com.android.volley.NoConnectionError: java.io.EOFException 0

我不知道为什么会出现这个错误。在与应用程序连接的示例中,我发送一些信息,如register_id,用于通知GCM,登录,密码和imei,有时我有此错误,显示为0_0

这是我的登录请求(但我的所有请求中都有此错误):

 public void connectDriver() {

    String url = UtilClass.getSytemValue("url_proxy",LoginConnection.this)+ ":"+ UtilClass.getSytemValue("port_proxy",LoginConnection.this) + "/api/driver/login";

        final ProgressDialog pDialog = new ProgressDialog(this);
        pDialog.setMessage("Connexion...");
        pDialog.show();
        Log.i("url", url);

        RequestQueue rq = Volley.newRequestQueue(this);
        StringRequest postReq = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d("response connection ", response);

                pDialog.dismiss();

                Gson gson = new Gson();
                final Driver driver = gson.fromJson(response.toString(), Driver.class);
                Log.i("DRIVER GSON", driver.toString());
                UtilClass.setSytemValue("driver_id",Integer.toString(driver.getId()),LoginConnection.this);

                driver.setLogin(mlogin);
                driver.setPass(util.md5(mPassword));

                if (driver.getSignature().isEmpty()) {
                    driver.setSignature(null);
                }

                final DriverQuery driverQuery = new DriverQuery(LoginConnection.this);
                driverQuery.open();
                long success = driverQuery.insertDriver(driver);
                driverQuery.close();
                Log.i("connection driver success : ",Long.toString(success));

                UtilClass.setSytemValue("driver_id",Integer.toString(driver.getId()),LoginConnection.this);
                Log.i("DRIVER SEND BEFORE GOTO", driver.toString());
                goTo(driver);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                pDialog.dismiss();
                int errorStatus = error.networkResponse != null ? error.networkResponse.statusCode
                        : 0;
                Log.i("Error ", error.toString() + " "
                        + errorStatus);

                AppController.getInstance().getRequestQueue()
                .stop();

                DriverQuery driverQuery = new DriverQuery(LoginConnection.this);
                driverQuery.open();
                Driver driver = driverQuery.getDriverExist(mlogin,util.md5(mPassword));

                if (driver.getId() != 0) {
                    goTo(driver);
                    UtilClass.setSytemValue("driver_id",Integer.toString(driver.getId()),LoginConnection.this);

                } else if (errorStatus == 500) {

                    AlertDialog ad = new AlertDialog.Builder(LoginConnection.this)
                    .setPositiveButton("Ok", null)
                    .setTitle("Problème")
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage("Un problème est survenue sur le serveur\nSi cela persiste , veuillez contacter l'administrateur")
                    .create();
                    ad.show();

                } else if (errorStatus == 400) {

                    AlertDialog ad = new AlertDialog.Builder(
                            LoginConnection.this)
                    .setPositiveButton("Ok", null)
                    .setTitle("Erreur")
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage("La syntaxe de la requête est erronée.\nSi cela persiste , veuillez contacter l'administrateur")
                    .create();
                    ad.show();

                } else if (errorStatus == 404) {

                    AlertDialog ad = new AlertDialog.Builder(LoginConnection.this)
                    .setPositiveButton("Ok", null)
                    .setTitle("Erreur")
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage("Identification incorrect.\nSi cela persiste , veuillez contacter l'administrateur")
                    .create();
                    ad.show();

                } else if (errorStatus == 0) {

                    AlertDialog ad = new AlertDialog.Builder(LoginConnection.this)
                    .setPositiveButton("Ok", null)
                    .setTitle("Erreur")
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage("Le temps d'attente a été dépassé.\nSi cela persiste , veuillez contacter l'administrateur")
                    .create();
                    ad.show();

                }
                driverQuery.close();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();

                params.put("login", mlogin);
                params.put("password", util.md5(mPassword));
                params.put("imei", getImei());
                params.put("registerId", UtilClass.getSytemValue("register_id", LoginConnection.this));

                Log.i("getParams", params.toString());
                return checkParams(params);
            }
              private Map<String, String> checkParams(Map<String, String> map){               
                    Iterator<Entry<String, String>> it = map.entrySet().iterator();
                    while (it.hasNext()) {
                        Map.Entry<String, String> pairs = (Map.Entry<String, String>)it.next();
                        if(pairs.getValue()==null){
                            map.put(pairs.getKey(), "");
                        }
                    }
                    return map;             
                }

        };

        // Adding request to request queue
        postReq.setRetryPolicy(new DefaultRetryPolicy(60 * 1000, 1,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));       
        AppController.getInstance().addToAndStartRequestQueue(postReq);         
        Log.i(TAG + " -> cache volley",Integer.toString(rq.getSequenceNumber()));


}

2 个答案:

答案 0 :(得分:2)

这是因为同时调用多个请求。我已经设置了优先级,它运行正常。

@Override
public Priority getPriority() {
    Request.Priority mPriority = Priority.HIGH;
    return mPriority;
}

注意:根据需要设置不同的优先级。

答案 1 :(得分:0)

在使StringRequest成为凌空之前对您的URL进行编码。或者仅编码您的请求结束参数。