齐射错误:找不到符号方法setRetryPolicy(DefaultRetryPolicy)

时间:2017-04-10 18:45:26

标签: android android-volley

  

Volley发送请求3次,所以我在下面添加了一行。   我希望凌空只发送一次请求

requestQueue.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
public void sendMessage(View view){
            StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String s) {

                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError volleyError) {
                            try {
                                Toast.makeText(EventDetailActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
                            }catch (Exception e){

                            }
                        }
                    }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {

                    String Status = ebtn.getText().toString().trim().toLowerCase();
                    SharedPreferences sharedPreferences = getSharedPreferences(SharedPrefConfig.SHARED_PREF_NAME,Context.MODE_PRIVATE);
                    String uname = sharedPreferences.getString(SharedPrefConfig.USERNAME_SHARED_PREF, null);
                    Map<String,String> params = new Hashtable<String, String>();
                    params.put("status", Status);
                    params.put("uname", uname);
                    params.put("dept", dept);
                    params.put("ename", name);
                    return params;
                }
            };
            RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
            requestQueue.add(stringRequest);
        }

1 个答案:

答案 0 :(得分:1)

setRetryPolicy()对象

中添加StringRequest

使用:

 stringRequest.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
你的代码中的

 public void sendMessage(View view){
    StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    try {
                        Toast.makeText(EventDetailActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
                    }catch (Exception e){

                    }
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {

            String Status = ebtn.getText().toString().trim().toLowerCase();
            SharedPreferences sharedPreferences = getSharedPreferences(SharedPrefConfig.SHARED_PREF_NAME,Context.MODE_PRIVATE);
            String uname = sharedPreferences.getString(SharedPrefConfig.USERNAME_SHARED_PREF, null);
            Map<String,String> params = new Hashtable<String, String>();
            params.put("status", Status);
            params.put("uname", uname);
            params.put("dept", dept);
            params.put("ename", name);
            return params;
        }
    };
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    stringRequest.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    requestQueue.add(stringRequest);
}