gpt4 book ai didi

安卓 Volley : Cannot resolve Constructor jsonobjectrequest

转载 作者:太空宇宙 更新时间:2023-11-03 13:52:30 24 4
gpt4 key购买 nike

我正在尝试使用 volley 来获取 JSON 并进行解析。但 android studio 说无法解析构造函数 jsonobjetrequest。我不明白这是什么错误。以下是代码。

JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, JSON_URL, null, new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {
try{
JSONArray routes = response.getJSONArray("routes");
}
catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
}
});

最佳答案

因为你的项目使用了mcxiaoke的volley,其中有如下两个构造函数:

public JsonObjectRequest(int method, String url, String requestBody,
Listener<JSONObject> listener, ErrorListener errorListener) {
super(method, url, requestBody, listener,
errorListener);
}

public JsonObjectRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONObject> listener, ErrorListener errorListener) {
super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener,
errorListener);
}

因此,如果您传递 null,则类无法知道要使用哪个构造函数。

如评论所述,您可以删除 Request.Method.GET,或删除 null,或转换为 (String)null(JSONObject)null

P/S:如果你的项目使用了谷歌官方的volley,那么你问题中的构造函数是正确的。

希望这对您有所帮助!

关于安卓 Volley : Cannot resolve Constructor jsonobjectrequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33428462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com