我正在構建一個新聞紙應用程序,因爲我需要在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