Strange. In all tutorials, the code is

url = "http://httpbin.org/post"; StringRequest postRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { // response Log.d("Response", response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // error Log.d("Error.Response", response); } } ) { @Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<String, String>(); params.put("name", "Alif"); params.put("domain", "http://itsalif.info"); return params; } }; queue.add(postRequest); 

But when I write a closing parenthesis after the errorListener compiler swears

 Missing , Unexcepted ) 

Here is my code

 StringRequest request = new StringRequest(Request.Method.POST, "http://pareto-marketing.ru/landlicense2.php?url=" + urlh + "&key=" + key + "&lastid", new Response.Listener<String>() { @Override public void onResponse(String response) { if(!response.endsWith("ключ")) { int serverId = Integer.parseInt(response.substring(1, response.length() -1)); int prefId = getLastPrefId(); if (prefId == 0) prefId = serverId; if (serverId > prefId) { showNotification(); setLastPrefId(serverId); } else setLastPrefId(serverId); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d("$", error.getCause().toString()); } }) //вот тут ); 
  • The code from the site was copied by url I replaced it with a string. As a result, all code was highlighted - Flippy
  • Help please, I already write 6 rasters in different ways and nothing happens - Flippy

1 answer 1

 public class PostRequest{ private RequestQueue mQueue; private Map<String, String> params; private String url; public String req; public PostRequest(Context context, String url, Map<String, String> params) { this.params = params; this.url = url; mQueue = Volley.newRequestQueue(context, new NukeSSLCerts()); } public void getString(final VolleyCallback callback) { StringRequest stringRequest = new StringRequest(Request.Method.POST, url , new Response.Listener<String>(){ @Override public void onResponse(String response) { req = response; callback.onSuccess(req); } } ,new Response.ErrorListener(){ @Override public void onErrorResponse(VolleyError error){ Log.d("VolleyError: " , error.getMessage()); } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { return params; } }; mQueue.add(stringRequest); } public interface VolleyCallback{ void onSuccess(String req); } } 

I created a separate class to send requests, I call as follows:

 final String[] payUrl = {null}; Map<String,String> params = new HashMap<>(); params.put("foo", "bar"); params.put("bar", "foo"); PostRequest getPay = new PostRequest(this,url,params); getPay.getString(new PostRequest.VolleyCallback() { @Override public void onSuccess(String req) { Log.d("reqInMainact", req); } }); 
  • Sorry, I already figured out, I just took out small parts from this huge constructor - Flippy