Skip to content

Instantly share code, notes, and snippets.

@marteinn
Created July 1, 2014 19:15
Show Gist options
  • Save marteinn/840f7ef91172261a6c0d to your computer and use it in GitHub Desktop.
Save marteinn/840f7ef91172261a6c0d to your computer and use it in GitHub Desktop.
Android Volley Samples: Catching a timeout error.
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;
import org.json.JSONObject;
Response.Listener<JSONObject> successListener = new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
// Pass
}
};
Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
if (volleyError.networkResponse == null) {
if (volleyError.getClass().equals(TimeoutError.class)) {
// Show timeout error message
Toast.makeText(getContext(),
"Oops. Timeout error!",
Toast.LENGTH_LONG).show();
}
}
}
});
Request<JSONObject> request = new JsonObjectRequest(Request.Method.GET, myUrl,
successListener, errorListener);
mQueue.add(request);
@Garyfimo
Copy link

Thank you so much!

@paragshedbale
Copy link

Thank you so much!

@dharmikkamani
Copy link

Thank You

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment