Android Volley post compilation error map

Asked

Viewed 124 times

0

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

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

inserir a descrição da imagem aqui

  • Hello dvd, I understood that you formatted my question. Thank you. I have difficulty editing because put the questions by mobile.

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 the onCreate

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

    requestQueue = Volley.newRequestQueue(this);
}

Afterward...

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.