我有这个代码,它填充了ArrayList(Bitmap)。但我无法收到Volley的回应。我已经放了一些日志来查看问题。我可以看到要运行的最后一个日志是"请求已发送"。我的清单中有INTERNET权限,链接(IMAGE_LINK)已启动并运行,服务器未关闭。可能是什么问题?
public class GetImages {
private ArrayList<Bitmap> images = new ArrayList<Bitmap>();
private ArrayList<String> links = new ArrayList<String>();
private Context context;
private Handler handler;
private String IMAGE_LINK = "http://10.95.56.134:8084/AppServer/JSON/image_try.json";
public GetImages(Context context, Handler handler)
{
Log.i("GetImages","Reached");
this.handler = handler;
this.context = context;
prepareImages();
}
public ArrayList<Bitmap> getImages()
{
return images;
}
public void prepareImages()
{
RequestQueue queue = VolleySingleton.getInstance(context)
.getRequestQueue();
JsonObjectRequest request = new JsonObjectRequest(
Request.Method.GET, IMAGE_LINK, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject json) {
try {
Log.i("Response","Received");
Integer total = Integer.parseInt(json.getString("total"));
Log.i("Total",String.valueOf(total));
for(int i = 0 ; i < total ; i ++)
{
links.add(json.getString("image"+(i+1)));
Log.i("Link "+i,links.get(links.size()-1));
}
getBitmap(total);
} catch (JSONException e) {
Log.i("Error Here",e.toString());
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
Log.i("Error",arg0.toString());
}
});
Log.i("Request","sent");
queue.add(request);
}
private void getBitmap(int total)
{
Log.i("Reached","here");
URL url = null;
HttpGet httpRequest = null;
HttpResponse response = null;
for(int j = 0 ; j < total ; j ++)
{
try {
url = new URL(links.get(j));
httpRequest = new HttpGet(url.toURI());
HttpClient httpclient = new DefaultHttpClient();
response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
InputStream input = null;
input = entity.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(input);
images.add(bitmap);
}
catch(Exception e) { Log.e("MyException",e.toString()); }
}
handler.sendEmptyMessage(0);
e}}