在這裏,我通過dalvikvm堆的一個.Getting錯誤下載從服務器的一個圖像:在31961104字節分配時內存運行應用程序,並在中途墜毀。一段時間圖像下載某個not.But我想從下載列表視圖中添加圖像..安卓:dalvikvm堆:內存
這裏是我的下載代碼
private Bitmap downloadBitmap(String url) {
final DefaultHttpClient client = new DefaultHttpClient();
final HttpGet getRequest = new HttpGet(url);
try {
HttpResponse response = client.execute(getRequest);
//check 200 OK for success
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w("ImageDownloader", "Error " + statusCode +
" while retrieving bitmap from " + url);
return null;
}
final HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
try {
// getting contents from the stream
inputStream = entity.getContent();
// decoding stream data back into image Bitmap that android understands
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
final Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, options);
// final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
File file = new File(newFolder, imageName);
if (file.exists()) file.delete();
try
{
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
int imagenObtenidaW = bitmap.getWidth();
int imagenObtenidaH = bitmap.getHeight();
Log.e("imagenObtenidaW " ," = +" + imagenObtenidaW + " imagenObtenidaH = " + imagenObtenidaH);
} catch (Exception e) {
}
return bitmap;
} finally {
if (inputStream != null) {
inputStream.close();
}
entity.consumeContent();
}
}
} catch (Exception e) {
// You Could provide a more explicit error message for IOException
getRequest.abort();
Log.e("ImageDownloader", "Something went wrong while" +
" retrieving bitmap from " + url + e.toString());
}
return null;
}
here is my code form download in the same Activity.
if (imageName.endsWith(png_Pattern) || imageName.endsWith(jpg_pattern) || imageName.endsWith(bmp_pattern) || imageName.endsWith(gif_pattern) || imageName.endsWith(jpeg_pattern))
{
str_DownLoadUrl = namespace + "/DownloadFile/FileName/" + imageName;
Log.e("@@@@@", "str_DownLoadUrl = " + str_DownLoadUrl);
//download_PngFile(str_DownLoadUrl);
downloadBitmap(str_DownLoadUrl);
strDownLoadStatus = "1";
dbhelper.update_DownLoadStatus(imageName, strDownLoadStatus);
}
}
這裏是我的logcat
1.414 10598-10601/com.example.tazeen.classnkk D/dalvikvm﹕ GC_CONCURRENT freed 1738K, 57% free 15379K/35335K, paused 5ms+7ms
10-13 14:52:11.963 10598-10826/com.example.tazeen.classnkk D/dalvikvm﹕ GC_FOR_ALLOC freed 64K, 57% free 15377K/35335K, paused 95ms
10-13 14:52:11.963 10598-10826/com.example.tazeen.classnkk I/dalvikvm-heap﹕ Forcing collection of SoftReferences for 31961104-byte allocation
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk D/dalvikvm﹕ GC_BEFORE_OOM freed 9K, 57% free 15368K/35335K, paused 68ms
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk E/dalvikvm-heap﹕ Out of memory on a 31961104-byte allocation.
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ "AsyncTask #2" prio=5 tid=13 RUNNABLE
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x42ad4188 self=0x1edbd8
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ | sysTid=10826 nice=10 sched=0/0 cgrp=bg_non_interactive handle=1591808
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ | schedstat=(12449561867 3389288161 878) utm=1181 stm=63 core=0
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at com.example.tazeen.classnkk.AllPosts_Page.downloadBitmap(AllPosts_Page.java:1220)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at com.example.tazeen.classnkk.AllPosts_Page.getDoenLoaddata(AllPosts_Page.java:738)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at com.example.tazeen.classnkk.AllPosts_Page$GetgetDoenLoaddata.doInBackground(AllPosts_Page.java:700)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at com.example.tazeen.classnkk.AllPosts_Page$GetgetDoenLoaddata.doInBackground(AllPosts_Page.java:696)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at android.os.AsyncTask$2.call(AsyncTask.java:264)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ at java.lang.Thread.run(Thread.java:856)
10-13 14:52:12.034 10598-10826/com.example.tazeen.classnkk I/dalvikvm﹕ [ 10-13 14:52:12.034 10598:0x2a4a D/skia ]
--- decoder->decode returned false
如何解決這個問題。
的完整鏈接的android:largeHeap = 「真」 做u設置此清單文件? –
爲什麼不使用圖像加載庫在列表視圖中添加圖像? –
加入'android:largerHeap =「true」'不是管理這個問題的正確方法。 –