zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

androidの异常:java.lang.IllegalStateException: ImageLoader must be init with configuration befor 错误解决方法

2023-09-27 14:27:47 时间

androidの异常:java.lang.IllegalStateException: ImageLoader must be init with configuration befor 错误解决方法

最近开发过程中用到了开源项目 Android-Universal-Image-Loader
在程序开发之前在CSDN的文章里看到的有Android-Universal-Image-Loader这么个好东西 ,用起来非常的方便,大家可以看Demo,里面有详细的介绍。
Android-Universal-Image-Loader 在使用的过程中碰到了一些问题。当时完全是按照官方的Demo来搭建的,但是始终程序运行不起来,会报以下错误:

java.lang.RuntimeException: ImageLoader must be init with configuration before using

字面意思是在使用前要初始化

只要加一句话:

解决的办法: 
protected ImageLoader imageLoader;

imageLoader = ImageLoader.getInstance(); 
imageLoader.init(ImageLoaderConfiguration.createDefault(this));

ps: 经小伙伴们提醒,官方demo中的初始化方法是在application类中调用的