Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoConnectionError in android volley

The following is my code. I get com.android.volley.NoConnectionError: java.io.InterruptedIOException for the first time and for the second time it works fine. There server response is also fine, No error in server side.

RequestQueue queue = Volley.newRequestQueue(MainActivity.this);

    JsonObjectRequest request = new JsonObjectRequest(URL, null,
            new Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject responseJsonObject) {
                    try {
                        if (responseJsonObject.has("user")
                                && !responseJsonObject
                                        .isNull("user")) {
                                user.jsonParser(responseJsonObject
                                    .getJSONObject("user"));
                        }
                    } catch (JSONException exception) {
                        Toast.makeText(context, "Error Occured",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            }, new ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    progressDialog.dismiss();
                    Log.d("Volley Error", volleyError.toString());
                    Toast.makeText(context, "Connectivity Error",
                            Toast.LENGTH_SHORT).show();
                }
            });

    queue.add(request);
    progressDialog.show();
    queue.start();
like image 358
nandha-dev Avatar asked Oct 31 '22 01:10

nandha-dev


1 Answers

I had the same problem and I solved it by removing the following line

queue.start()
like image 198
matdev Avatar answered Nov 15 '22 05:11

matdev