Volley Timeout Error

前端 未结 13 1052
清歌不尽
清歌不尽 2020-12-01 14:31

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/stewayservic         


        
相关标签:
13条回答
  • 2020-12-01 15:00

    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!

    0 讨论(0)
  • 2020-12-01 15:00
    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();
                    }
    
    0 讨论(0)
  • 2020-12-01 15:00
    stringRequest.setRetryPolicy(new DefaultRetryPolicy(
                    6000,
                    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
            );
    
    0 讨论(0)
  • 2020-12-01 15:00

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

    0 讨论(0)
  • 2020-12-01 15:05

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

    0 讨论(0)
  • 2020-12-01 15:08
    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);
    
    0 讨论(0)
提交回复
热议问题