Compililation Error while using JsonObjectRequest

前端 未结 3 1300
轻奢々
轻奢々 2021-02-04 13:40

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

Error:(77, 37) error: reference to JsonObjectRequest is ambiguous, both constructor 
         


        
相关标签:
3条回答
  • 2021-02-04 14:13

    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) {
    
        }
    });
    
    0 讨论(0)
  • 2021-02-04 14:17

    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>()
    
    0 讨论(0)
  • 2021-02-04 14:27

    You just used null reference.

    new JsonObjectRequest(Request.Method.GET,
            getRequestUrl(10),
            (String)null,
            new Response.Listener<JSONObject>()
    

    its work for me

    0 讨论(0)
提交回复
热议问题