夜空泪 2015-04-15 13:16 采纳率: 60%
浏览 2237
已采纳

为什么Universal的ImageLoader 老是说没有配置对

public class GlobalApplication extends Application {

public static ImageLoader imageLoader = ImageLoader.getInstance();

public static DisplayImageOptions options;

@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    initImageLoader(getApplicationContext());
    options = new DisplayImageOptions.Builder()
            .showStubImage(R.drawable.ic_launcher)// 加载等待 时显示的图片
            .showImageForEmptyUri(R.drawable.ic_launcher)// 加载数据为空时显示的图片
            .showImageOnFail(R.drawable.ic_launcher)// 加载失败时显示的图片
            .cacheInMemory().cacheOnDisc() /**
             * .displayer(new
             * RoundedBitmapDisplayer(20))
             **/
            .build();
}

public static void initImageLoader(Context context) {
    // This configuration tuning is custom. You can tune every option, you
    // may tune some of them,
    // or you can create default configuration by
    // ImageLoaderConfiguration.createDefault(this);
    // method.
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            context).threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            //软引用和强引用结合
            //FIFOLimitedMemoryCache(先进先出的缓存策略,当超过设定值,先删除最先加入缓存的bitmap)
            .memoryCache(new FIFOLimitedMemoryCache(2*1024*1024))
            // default为使用HASHCODE对UIL进行加密命名, 还可以用MD5(new Md5FileNameGenerator())加密
            //.diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) 
            .discCacheSize(50*1024*1024)
            .discCacheFileCount(100)
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging() // Not
            .build();
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config);
    // imageLoader.init(ImageLoaderConfiguration.createDefault(context));

}

}

这是在Application里的配置

public class HeadFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    View view = inflater.inflate(R.layout.headfragment,container,false);
    ImageView iv = (ImageView) view.findViewById(R.id.head_iv);
    Bundle bundle = getArguments();
    String headImageUrl = bundle.getString("headImageUrl");
    Log.e("headImageUrl", headImageUrl);
    GlobalApplication.imageLoader.displayImage(headImageUrl, iv,GlobalApplication.options);
    return view;
}

}

这是用到的时候ImageLoader的时候。

但是老是报错,怎么回事啊
图片说明

  • 写回答

3条回答 默认 最新

  • bdmh 移动开发领域优质创作者 2015-04-15 13:28
    关注

    你确认你调用了 GlobalApplication的create了吗,有没有在mainfest文件中指定这个 GlobalApplication

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名