android volley请求永远不会发生

时间:2018-01-15 01:14:25

标签: java android android-volley

我是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();
    }

0 个答案:

没有答案