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();
I had the same problem and I solved it by removing the following line
queue.start()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With