4 votes

Volley TimeOutError. Android Studio

I happen to be working with volley. When I want to fill a Recyclerview I get the error described in the title, I've been reading and I know it's because of the response time between the application and the server (in this case), I tried different solutions that ended up affecting the project (for example I was closed). If you need any other part of the code let me know, although this should be enough because I know that this part of the code is used to implement the timing.

JsonObjectRequest jsonObjectRequest;

        listaProducto = new ArrayList<>();

        recyclerProducto = (RecyclerView) vista.findViewById(R.id.listaTodasRec);
        recyclerProducto.setLayoutManager(new LinearLayoutManager(this.getContext()));

        request = Volley.newRequestQueue(getContext());


        return vista;

    private void cargarWebService() {
        progress = new ProgressDialog(getContext());
        progress.setMessage("Buscando productos..");

        String url = "";

        jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,url,null,this,this);

    public void onErrorResponse(VolleyError error) {
        Toast.makeText(getContext(), "No se puede conectar, error: "+error.toString(), Toast.LENGTH_LONG).show();
        Log.d("Error: ", error.toString());

    public void onResponse(JSONObject response) {
        Productos productos= null;
        JSONArray json = response.optJSONArray("productos");

            for (int i = 0; i<json.length();i++)
                productos= new Productos();
                JSONObject jsonObject = null;
                jsonObject = json.getJSONObject(i);


            ProductosAdapters adapters = new ProductosAdapters (listaProductos);
        catch (JSONException e){
            Toast.makeText(getContext(), "No se ha podido conectar con el servidor" + " " + response, Toast.LENGTH_LONG).show();


0 votes

I see that you make the request locally, do you have apache enabled so that Volley can connect to your Web-Service?


A. Cedano Points 48884

I remember having a similar problem in the past and I solved it as follows:

  1. Declaring a constant MY_DEFAULT_TIMEOUT

In my case, this constant is in my class Constants which I then import wherever I need them. I have given it a value of 15000 :

public class Constants {

    public static final int MY_DEFAULT_TIMEOUT = 15000;

  1. Establish a retry policy in my Volley request using the setRetryPolicy in which I use my constant.

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(

This should be done before adding the request to the queue that is, before this line:


Since then I have not had any more timeout problems.

If it still does not work, you should check that there is no problem with the URL. by testing it from the browser for example or by checking the PHP error log.

If all is well on that side and it still doesn't work, consider increasing the value of the constant, at least for requests that are too long. Or... consider optimizing the code on the server or the database. Sometimes responses are slow because the PHP code is not optimized, or because the indexes in the database are not the right ones, etc.

1 votes

Thank you very much friend !!!!! It served me perfectly and very well explained by the way, I would give you many likes but I can only give you one hahaha, I'm really very grateful! :D


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: