Volley Timeout Error
Asked Answered
N

13

26

I am trying to hit a rest service using Volley.

public class AuthFunctions {
    private static final String LOGIN_URL = "http://10.0.2.2:8080/stewayservices/user-management/users/10";
    boolean result;
    public boolean loginUser(String email,String password){

        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET,LOGIN_URL,null,new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.d("JsonObject Response",response.toString());
                try {
                    JSONObject user = response.getJSONObject("user");
                    String firstName = user.getString("firstName");
                    if (firstName.equals("Lokesh")){
                        result = true;
                    }
                    else{
                        result = false;
                    }
                } catch (JSONException e) {
                    Log.d("Web Service Error",e.getMessage());
                    e.printStackTrace();
                }
            }
        },new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.d("JsonObject Error Response",volleyError.toString());
            }
        });
        request.setRetryPolicy(new DefaultRetryPolicy(500000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        AppController.getInstance().addToRequestQueue(request);
        return result;
    }
}

But it is giving me the Volley Timeout error. Below is the Logcat

 D/JsonObject Error Response﹕ com.android.volley.TimeoutError

Please let me know know if I am doing it wrong. This is my first question in stackoverflow regarding Android.

Netti answered 23/9, 2014 at 11:57 Comment(2)
are you sure about your connecting to your localhost? is your server listening at port 8080? is your firewall off?Disproof
Did you get any solution?Disinterest
D
53

This worked for me:

request.setRetryPolicy(new RetryPolicy() {
            @Override
            public int getCurrentTimeout() {
                return 50000;
            }

            @Override
            public int getCurrentRetryCount() {
                return 50000;
            }

            @Override
            public void retry(VolleyError error) throws VolleyError {

            }
        });

You can change that time.

Dunigan answered 8/11, 2015 at 23:24 Comment(2)
or shorter: request.setRetryPolicy(new DefaultRetryPolicy( 50000, 5, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));Demilune
@Demilune your solution was so helpful! Daalu nwanne!!Tabriz
U
19
com.android.volley.TimeoutError

In 75% cases this error is occured due to connectivity issue '

if you are testing on localhost or local server

Check firewall is off

Unitary answered 19/12, 2016 at 15:5 Comment(1)
it works fine good answer after disabling fire wall in my system it workedChelton
T
5
String url = "https://api.joind.in/v2.1/events?start=" + start + "&resultsperpage=20&format=json";
Log.i("DREG", "onLoadMoreItems: " + url);
final StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                // Add Code Here
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                    Toast.makeText(getContext(),
                            "Oops. Timeout error!",
                            Toast.LENGTH_LONG).show();
                }
            }
        }
);
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
        10000,
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(stringRequest);
Tacy answered 21/9, 2017 at 6:49 Comment(0)
O
4
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
                6000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
        );
Ouidaouija answered 2/7, 2019 at 10:21 Comment(0)
F
3
public void onErrorResponse(VolleyError error) {
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                    Toast.makeText(getContext(),
                            "Oops. Timeout error!",
                            Toast.LENGTH_LONG).show();
                }
Fireworm answered 12/3, 2018 at 6:57 Comment(0)
A
2

Volley throws timeouterror when it couldn't connect to the url provided in request. reasons could be:

1)connectivity. 2)Url is not valid.

Try running it on emulator.It should work on emulator as emualator runs on same machine and has same ip as your wamp running on.

To make it work on real device connect your device to same WLAN as your wampserver is running on. If not connected to same WLAN you have to host your php scripts to web. To do this there are many free web hosting sites like https://www.000webhost.com/ are available check them out.

Hope this help!

Austreng answered 5/7, 2017 at 7:23 Comment(0)
E
2

Add the following after your error listener

myRequest.setRetryPolicy(new DefaultRetryPolicy(
    MY_SOCKET_TIMEOUT_MS, 
    DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Episodic answered 7/8, 2018 at 5:20 Comment(0)
G
1

Check out that your IPv4 Address in the URL is correct and has not been changed.

Gainor answered 13/2, 2019 at 14:15 Comment(0)
A
1

On Macbook I was running a Django application written in python3.X.
I had to do the following.

  1. Go to system settings
  2. Go to Security & Privacy
  3. Select the firewall tab and click on the firewall options
  4. Allow incoming connection for python 3.7

enter image description here

Afloat answered 11/5, 2019 at 11:3 Comment(0)
V
0

The same occurred to me, because I did not started my Xampp. I think may be the same.

Varitype answered 23/4, 2019 at 15:31 Comment(0)
G
0

5 year old question is tough to deal with today's problem.

Volley will no more accept http and ip address. Will accept only https with fqdn only.

Gambrel answered 6/12, 2019 at 12:25 Comment(0)
E
0

use retry policy like this

request.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 2, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

requestQueue.add(request);
Everetteverette answered 10/9, 2020 at 7:20 Comment(0)
D
-3

This happened to me. I determined that the problem happened because I did not start Apache and MySQL in XAMPP.

Delorisdelorme answered 10/8, 2018 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.