Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compililation Error while using JsonObjectRequest

I'm using mcxiaoke/android-volley library.Im getting compilation error as

Error:(77, 37) error: reference to JsonObjectRequest is ambiguous, both constructor 
JsonObjectRequest(int,String,String,Listener<JSONObject>,ErrorListener) in JsonObjectRequest and constructor 
JsonObjectRequest(int,String,JSONObject,Listener<JSONObject>,ErrorListener) in JsonObjectRequest match

this is my code.I dont know what is wrong. Any help appreciated

JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET,
            getRequestUrl(10),
            null,
            new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {


        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });
like image 426
Harish Avatar asked Mar 17 '15 17:03

Harish


2 Answers

Cast the null to string or JSONObject and it should work fine i think.

new JsonObjectRequest(Request.Method.GET,
            getRequestUrl(10),
            (String)null,
            new Response.Listener<JSONObject>()
like image 56
null pointer Avatar answered Oct 29 '22 15:10

null pointer


Bill Gates is right, there is no way for that class to know which constructor to use if you pass in null instead of the Object of type String or JSONObject it is expecting in one of the constructors otherwise you will get this ambiguous error, saying that the constructor has 2 matches.

Try:

 JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET,
        getRequestUrl(10),
        "",
        new Response.Listener<JSONObject>() {
    @Override
    public void onResponse(JSONObject response) {


    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {

    }
});
like image 28
kandroidj Avatar answered Oct 29 '22 16:10

kandroidj