如何从try catch块中获取数据?

时间:2015-09-08 13:13:07

标签: java android json exception

final ArrayList<String> pic = new ArrayList<String>();
final ArrayList<String> name = new ArrayList<String>();
RequestQueue mQueue = Volley.newRequestQueue(this);
    JsonArrayRequest req = new JsonArrayRequest(url,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    try {
                        for (int i = 0; i < response.length(); i++)
                        {
                            JSONObject jobj = response.getJSONObject(i);
                            name.add(jobj.getString("name"));
                            pic.add(jobj.getString("pic"));
                        }
                        txt1.setText(name.toString());
                    }
                    catch (JSONException e) {                        }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("TAG", "Error: " + error.getMessage());
        }
    });
    txt.setText(pic.toString());
    mQueue.add(req);
尝试中的

name.toString不为空(例如:[a,b,c,d]),但如果我将其移出,请尝试pic.toString数组为空(例如:[])

0 个答案:

没有答案