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
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!
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(
6000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
);
This happened to me. I determined that the problem happened because I did not start Apache and MySQL in XAMPP.
The same occurred to me, because I did not started my Xampp. I think may be the same.
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);