nostra13/Android-Universal-Image-Loader · error · IllegalStateException
ImageLoader must be init with configuration before using
Error message
ImageLoader must be init with configuration before using
What it means
Almost every public ImageLoader method (displayImage, loadImage, getMemoryCache, getDiskCache, clearMemoryCache, ...) begins with checkConfiguration(), which throws IllegalStateException(ERROR_NOT_INIT) when the singleton's configuration field is null, i.e. init(ImageLoaderConfiguration) was never called (or destroy() was called). The engine, caches and executors all live in that configuration, so calling any API before init is a programming error, not a recoverable condition.
Source
Thrown at library/src/main/java/com/nostra13/universalimageloader/core/ImageLoader.java:613
public Bitmap loadImageSync(String uri, ImageSize targetImageSize, DisplayImageOptions options) {
if (options == null) {
options = configuration.defaultDisplayImageOptions;
}
options = new DisplayImageOptions.Builder().cloneFrom(options).syncLoading(true).build();
SyncImageLoadingListener listener = new SyncImageLoadingListener();
loadImage(uri, targetImageSize, options, listener);
return listener.getLoadedBitmap();
}
/**
* Checks if ImageLoader's configuration was initialized
*
* @throws IllegalStateException if configuration wasn't initialized
*/
private void checkConfiguration() {
if (configuration == null) {
throw new IllegalStateException(ERROR_NOT_INIT);
}
}
/** Sets a default loading listener for all display and loading tasks. */
public void setDefaultLoadingListener(ImageLoadingListener listener) {
defaultListener = listener == null ? new SimpleImageLoadingListener() : listener;
}
/**
* Returns memory cache
*
* @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
*/
public MemoryCache getMemoryCache() {
checkConfiguration();
return configuration.memoryCache;
}
View on GitHub (pinned to ba33ec64d0)
Solutions
- Call ImageLoader.getInstance().init(new ImageLoaderConfiguration.Builder(context).build()) in Application.onCreate()
- After destroy(), re-init before any further use (init creates a fresh engine)
- Guard optional entry points with ImageLoader.getInstance().isInited()
Example fix
// before
public class MyActivity extends Activity {
protected void onCreate(Bundle b) {
ImageLoader.getInstance().displayImage(uri, imageView); // IllegalStateException
}
}
// after
public class App extends Application {
@Override public void onCreate() {
super.onCreate();
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
}
} Defensive patterns
Strategy: validation
Validate before calling
if (!ImageLoader.getInstance().isInited()) {
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(context));
}
ImageLoader.getInstance().displayImage(uri, imageView); Try / catch
try {
ImageLoader.getInstance().displayImage(uri, imageView);
} catch (IllegalStateException e) {
ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(appContext));
ImageLoader.getInstance().displayImage(uri, imageView);
} Prevention
- Initialize once in Application.onCreate() and assert isInited() in debug builds
- Re-init after destroy() before any further ImageLoader API call
- Centralize all ImageLoader access behind one app-owned wrapper
When it happens
Trigger: Calling ImageLoader.getInstance().displayImage(...) from an Activity before Application.onCreate ran init(); calling any API after ImageLoader.destroy(); library code paths where a Service or ContentProvider starts before the Application class.
Common situations: Forgetting init() in a demo or after refactoring the Application class; process death restoring an Activity while init was skipped due to an early-return/exception in Application.onCreate; calling ImageLoader APIs in unit tests on the JVM without Robolectric init; calling after destroy() in a logout flow.
Related errors
- ImageLoader configuration can not be initialized with null
- Wrong arguments were passed to displayImage() method (ImageV
- cache is closed
- LineReader is closed
- key == null
AI-assisted analysis of nostra13/Android-Universal-Image-Loader@ba33ec64d0 (2026-08-14).
Data as JSON: /api/errors/b203d59c18a3d91a.
Report an issue: GitHub.