Android volley post compilation error map

0

Hello, The code below only compiles if I comment the map section, but I need it to populate the parameters of the post.

  

Erros: method onresponse onerrorresponse does not override its superclass

     

There is no applicable Constructor to 'int, java.lang.String, com.mycompany.AgendaConsulado.MainActivity.(anonymous), com.mycompany.AgendaConsulado.MainActivity.(anonymous))'

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);

    
asked by anonymous 23.12.2017 / 21:46

1 answer

1

Try this way

//Variaveis Globais
private static final String URL = "http://httpbin.org/post";
JSONObject js = new JSONObject();
private RequestQueue requestQueue;
private JsonObjectRequest request;

Inside of onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestQueue = Volley.newRequestQueue(this);
}

Then ...

try {
        js.put("name", "Alif");
        js.put("domain", "http://itsalif.info");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    request = new JsonObjectRequest(Request.Method.POST, URL, js, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject jsonObject = new JSONObject(response.toString());

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }
    };

    requestQueue.add(request);
}
    
25.12.2017 / 12:43