使用 JsonObjectRequest 时出现编译错误

Compililation Error while using JsonObjectRequest

我正在使用 mcxiaoke/android-volley library.Im 得到编译错误

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

这是我的 code.I 不知道哪里出了问题。任何帮助表示赞赏

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

        }
    });

将 null 转换为字符串或 JSONObject,我认为它应该可以正常工作。

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

Bill Gates 是对的,class 如果您传入 null 而不是它在其中一个构造函数中期望的 String 或 JSONObject 类型的对象,则无法知道要使用哪个构造函数你会得到这个模棱两可的错误,说构造函数有 2 个匹配项。

尝试:

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

    }
});

您刚刚使用了空引用。

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

对我有用