1
我試圖從Web服務中檢索圖像和文本的列表。我已經第一次編碼,使用簡單適配器將圖像顯示到列表中。這些圖像顯示得到應用是否顯示錯誤,並在logcat中會出現以下錯誤...內存不足錯誤
04-26 10:55:39.483: ERROR/dalvikvm-heap(1047): 8850-byte external allocation too large for this process.
04-26 10:55:39.493: ERROR/(1047): VM won't let us allocate 8850 bytes
04-26 10:55:39.563: ERROR/AndroidRuntime(1047): Uncaught handler: thread Thread-96 exiting due to uncaught exception
04-26 10:55:39.573: ERROR/AndroidRuntime(1047): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-26 10:55:39.573: ERROR/AndroidRuntime(1047): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-26 10:55:39.573: ERROR/AndroidRuntime(1047): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:451)
04-26 10:55:39.573: ERROR/AndroidRuntime(1047): at com.stellent.gorinka.AsyncImageLoaderv.loadImageFromUrl(AsyncImageLoaderv.java:57)
04-26 10:55:39.573: ERROR/AndroidRuntime(1047): at com.stellent.gorinka.AsyncImageLoaderv$2.run(AsyncImageLoaderv.java:41)
04-26 10:55:40.393: ERROR/dalvikvm-heap(1047): 14600-byte external allocation too large for this process.
04-26 10:55:40.403: ERROR/(1047): VM won't let us allocate 14600 bytes
04-26 10:55:40.493: ERROR/AndroidRuntime(1047): Uncaught handler: thread Thread-93 exiting due to uncaught exception
04-26 10:55:40.493: ERROR/AndroidRuntime(1047): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-26 10:55:40.493: ERROR/AndroidRuntime(1047): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-26 10:55:40.493: ERROR/AndroidRuntime(1047): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:451)
04-26 10:55:40.493: ERROR/AndroidRuntime(1047): at com.stellent.gorinka.AsyncImageLoaderv.loadImageFromUrl(AsyncImageLoaderv.java:57)
04-26 10:55:40.493: ERROR/AndroidRuntime(1047): at com.stellent.gorinka.AsyncImageLoaderv$2.run(AsyncImageLoaderv.java:41)
04-26 10:55:40.594: INFO/Process(584): Sending signal. PID: 1047 SIG: 3
這裏的適配器中編碼...
final ImageView imageView = (ImageView) rowView.findViewById(R.id.image);
AsyncImageLoaderv asyncImageLoader=new AsyncImageLoaderv();
Bitmap cachedImage = asyncImageLoader.loadDrawable(imgPath, new AsyncImageLoaderv.ImageCallback() {
public void imageLoaded(Bitmap imageDrawable, String imageUrl) {
imageView.setImageBitmap(imageDrawable);
}
});
imageView.setImageBitmap(cachedImage);
要加載的圖像。 ..
public static Bitmap loadImageFromUrl(String url) {
InputStream inputStream;Bitmap b;
try {
inputStream = (InputStream) new URL(url).getContent();
BitmapFactory.Options bpo= new BitmapFactory.Options();
bpo.inSampleSize=2;
b=BitmapFactory.decodeStream(inputStream, null,bpo);
return b;
} catch (IOException e) {
throw new RuntimeException(e);
}
//return null;
}
請告訴我如何修正這個錯誤....
您需要嘗試在此鏈接中實現代碼 http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object – AnilPatel 2013-04-24 12:50:08