我是android初学者,可以帮助我解决我的问题,我需要让Volley请求同步。我找到了解决方案,我sholud使用RequestFuture,但响应永远不会发生。你能告诉我哪里出错了吗?
RequestFuture<JSONArray> future = RequestFuture.newFuture();
requestQueue = Volley.newRequestQueue(context);
Images = new ArrayList<>();
JsonArrayRequest request = new JsonArrayRequest(Request.Method.POST, showUrl, future, future) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("catalogID", s);
return params;
}
};
try {
JSONArray response = future.get(30, TimeUnit.SECONDS);
Log.e("test", "test");
int length = response.length();
JSONObject jsonObject;
for (int i = 0; i < length; i++) {
jsonObject = response.getJSONObject(i);
String path = jsonObject.getString("Path");
Images.add(path);
notifyDataSetChanged();
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
} catch (TimeoutException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}