Android - 图片加载器错误
Android - Image Loader Error
当我想显示左侧菜单时出现此异常。有人知道如何解决这个问题吗?
Caused by: java.lang.IllegalStateException: ImageLoader must be init with configuration before using
at com.nostra13.universalimageloader.core.ImageLoader.checkConfiguration(ImageLoader.java:568)
at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:208)
at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:365)
at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:340)
at com.csform.android.uiapptemplate.util.ImageUtil.displayRoundImage(ImageUtil.java:29)
at com.csform.android.uiapptemplate.LeftMenusActivity.prepareHeaderView(LeftMenusActivity.java:120)
at com.csform.android.uiapptemplate.LeftMenusActivity.setAdapter(LeftMenusActivity.java:97)
at com.csform.android.uiapptemplate.LeftMenusActivity.onCreate(LeftMenusActivity.java:64)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access0(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
这是我要显示的代码
public static void displayRoundImage(ImageView view, String path, ImageLoadingListener listener) {
ImageLoader loader = ImageLoader.getInstance();
try {
loader.displayImage(path, view, ROUND_DISPLAY_IMAGE_OPTIONS, listener);
} catch (OutOfMemoryError e) {
e.printStackTrace();
loader.clearMemoryCache();
}
}
这是调用方法的代码
private View prepareHeaderView(int layoutRes, String url, String email) {
View headerView = getLayoutInflater().inflate(layoutRes, mDrawerList,
false);
ImageView iv = (ImageView) headerView.findViewById(R.id.image);
TextView tv = (TextView) headerView.findViewById(R.id.email);
ImageUtil.displayRoundImage(iv, url, null);
tv.setText(email);
return headerView;
}
实际上我不知道为什么会出现此错误。我试图初始化它,但我失败了。谁能帮帮我?
抱歉,伙计们,我通过将其添加到我的 onCreate 方法中解决了我的问题
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
但是,谢谢大家的帮助。
嗨,请像这样在 onCreate() 中初始化 ImageLoader 配置...
在class
之外声明
private ImageLoader imageLoader = ImageLoader.getInstance();
private DisplayImageOptions options;
然后在onCreate()
里面
imageLoader.init(ImageLoaderConfiguration.createDefault(getBaseContext()));
options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.image_not_avbl).showImageOnFail(R.drawable.image_not_avbl)
// HERE
.bitmapConfig(Bitmap.Config.RGB_565).cacheOnDisc(true).delayBeforeLoading(0).cacheInMemory(true).resetViewBeforeLoading(false)
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).build();
快乐编码:-)
当我想显示左侧菜单时出现此异常。有人知道如何解决这个问题吗?
Caused by: java.lang.IllegalStateException: ImageLoader must be init with configuration before using
at com.nostra13.universalimageloader.core.ImageLoader.checkConfiguration(ImageLoader.java:568)
at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:208)
at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:365)
at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:340)
at com.csform.android.uiapptemplate.util.ImageUtil.displayRoundImage(ImageUtil.java:29)
at com.csform.android.uiapptemplate.LeftMenusActivity.prepareHeaderView(LeftMenusActivity.java:120)
at com.csform.android.uiapptemplate.LeftMenusActivity.setAdapter(LeftMenusActivity.java:97)
at com.csform.android.uiapptemplate.LeftMenusActivity.onCreate(LeftMenusActivity.java:64)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access0(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
这是我要显示的代码
public static void displayRoundImage(ImageView view, String path, ImageLoadingListener listener) {
ImageLoader loader = ImageLoader.getInstance();
try {
loader.displayImage(path, view, ROUND_DISPLAY_IMAGE_OPTIONS, listener);
} catch (OutOfMemoryError e) {
e.printStackTrace();
loader.clearMemoryCache();
}
}
这是调用方法的代码
private View prepareHeaderView(int layoutRes, String url, String email) {
View headerView = getLayoutInflater().inflate(layoutRes, mDrawerList,
false);
ImageView iv = (ImageView) headerView.findViewById(R.id.image);
TextView tv = (TextView) headerView.findViewById(R.id.email);
ImageUtil.displayRoundImage(iv, url, null);
tv.setText(email);
return headerView;
}
实际上我不知道为什么会出现此错误。我试图初始化它,但我失败了。谁能帮帮我?
抱歉,伙计们,我通过将其添加到我的 onCreate 方法中解决了我的问题
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
但是,谢谢大家的帮助。
嗨,请像这样在 onCreate() 中初始化 ImageLoader 配置... 在class
之外声明private ImageLoader imageLoader = ImageLoader.getInstance();
private DisplayImageOptions options;
然后在onCreate()
里面imageLoader.init(ImageLoaderConfiguration.createDefault(getBaseContext()));
options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.image_not_avbl).showImageOnFail(R.drawable.image_not_avbl)
// HERE
.bitmapConfig(Bitmap.Config.RGB_565).cacheOnDisc(true).delayBeforeLoading(0).cacheInMemory(true).resetViewBeforeLoading(false)
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).build();
快乐编码:-)