1

I got this exception when i want to show my left menu. Anyone know how to solve this?

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.access$800(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)

this is my code to display

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();
    }
}

this is code to call the method

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;
}

actually i dont know why i got this error. I tried to init it, but i failed. Anyone can help me?

2 Answers2

1

Sorry guys, somehow i solve my problem with add this to my onCreate method

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

But, thanks all for your help.

0

HI please initialize ImageLoader config in onCreate() like this way... Declare it outside of class

private ImageLoader imageLoader = ImageLoader.getInstance();
private DisplayImageOptions options;

And then inside 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();

Happy Coding :-)