我正在开发一个Android应用程序,要求我在运行时从服务器上获取一些图像,所以我得到它缩略图,然后使用Android-Universal-ImageLoader来得到这些图片:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).build();
ImageLoader.getInstance().init(config);
// to get the movie_poster from the server
private void setImageResource_season(ImageButton image, String url){
loader = ImageLoader.getInstance();
loader.displayImage(url, image);
}
当它有少量图像时,一切顺利,但当它与 100 图像相似时ImageLoader
给我的感觉就像 10 < / strong>到 15 图片然后它传递给我异常:
02-19 15:14:30.018: ERROR/dalvikvm-heap(597): Out of memory on a 1382416-byte allocation.
02-19 15:14:30.018: INFO/dalvikvm(597): "uil-pool-1-thread-1" prio=4 tid=16 RUNNABLE
02-19 15:14:30.018: INFO/dalvikvm(597): | group="main" sCount=0 dsCount=0 obj=0x413f6e18 self=0x1e05c8
02-19 15:14:30.018: INFO/dalvikvm(597): | sysTid=649 nice=10 sched=0/0 cgrp=bg_non_interactive handle=2031848
02-19 15:14:30.018: INFO/dalvikvm(597): | schedstat=( 17149851689 41024927609 1804 ) utm=1582 stm=132 core=0
02-19 15:14:30.018: INFO/dalvikvm(597): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
02-19 15:14:30.018: INFO/dalvikvm(597): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:78)
02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:289)
02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:245)
02-19 15:14:30.018: INFO/dalvikvm(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:141)
02-19 15:14:30.018: INFO/dalvikvm(597): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-19 15:14:30.018: INFO/dalvikvm(597): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-19 15:14:30.018: INFO/dalvikvm(597): at java.lang.Thread.run(Thread.java:856)
02-19 15:14:30.108: DEBUG/skia(597): --- decoder->decode returned false
02-19 15:15:10.008: ERROR/ImageLoader(597): null
02-19 15:15:10.008: ERROR/ImageLoader(597): java.lang.OutOfMemoryError
02-19 15:15:10.008: ERROR/ImageLoader(597): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
02-19 15:15:10.008: ERROR/ImageLoader(597): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:78)
02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:289)
02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:245)
02-19 15:15:10.008: ERROR/ImageLoader(597): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:141)
02-19 15:15:10.008: ERROR/ImageLoader(597): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-19 15:15:10.008: ERROR/ImageLoader(597): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-19 15:15:10.008: ERROR/ImageLoader(597): at java.lang.Thread.run(Thread.java:856)
答案 0 :(得分:0)
添加
android:largeHeap="true"
在你的清单application tag
内
实施例
<application
android:allowBackup="true"
android:largeHeap="true"
android:icon="@drawable/ic_launcher" >