我正在构建一个新闻纸应用程序,因为我需要在gallary视图中显示新闻纸张图像(epaper)...我需要下载大约100张图像。为此,我使用asyncTask和每个下载图像创建新的AsyncTask对象,并且当我尝试下载图像并将其设置为gallary时,我在中间出现错误“VM不会让我们分配......字节”并崩溃应用程序。虚拟机不会让我们分配...下载图片时的字节数
new AsyncTask<String, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(String... params) {
HttpGet httpRequest;
try {
httpRequest = new HttpGet(new URL(params[0]).toURI());
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpClient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream is = bufHttpEntity.getContent();
return BitmapFactory.decodeStream(is);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}/* catch (Error e) {
e.printStackTrace();
}*/
return null;
}
@Override
protected void onPostExecute(Bitmap result) {
if(result != null) {
img.setImageBitmap(ePaperInfo.getImgJpg1());
notifyDataSetChanged();
}
}
}
显示错误的logcat:
请帮我
在此先感谢。
感谢您的回放,但我需要存储这些所有图像,因为我需要在“galleryview”中显示所有图像。 –
好吧,那么你应该尝试实现你的适配器,像我上面发布的ImageDownloader示例:) – Zelleriation