Android Volley:无法解析构造函数 jsonobjectrequest
Android Volley: Cannot resolve Constructor jsonobjectrequest
我正在尝试使用截击来获取 JSON 并进行解析。但是 android 工作室说无法解析构造函数 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
,class 将无法知道要使用哪个构造函数。
如评论所述,您可以删除 Request.Method.GET
,或删除 null
,或转换为 (String)null
或 (JSONObject)null
。
P/S:如果你的项目使用了Google的官方volley,你问题中的构造函数是正确的
希望对您有所帮助!
我正在尝试使用截击来获取 JSON 并进行解析。但是 android 工作室说无法解析构造函数 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
,class 将无法知道要使用哪个构造函数。
如评论所述,您可以删除 Request.Method.GET
,或删除 null
,或转换为 (String)null
或 (JSONObject)null
。
P/S:如果你的项目使用了Google的官方volley,你问题中的构造函数是正确的
希望对您有所帮助!