Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

android - Volley Timeout Error

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...