我正在构建一个新闻纸应用程序,我需要在画廊视图中显示新闻纸图像(电子纸)......我需要下载大约 100 张图像。为此,我使用 asyncTask 并为每个下载图像创建新的 AsyncTask 对象,当我尝试下载图像并设置到库中时,中间出现错误“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 中显示错误:
请帮我
提前致谢。