{"record":{"id":"b203d59c18a3d91a","repo":"nostra13/Android-Universal-Image-Loader","slug":"imageloader-must-be-init-with-configuration-before","errorCode":null,"errorMessage":"ImageLoader must be init with configuration before using","messagePattern":"ImageLoader must be init with configuration before using","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/core/ImageLoader.java","lineNumber":613,"sourceCode":"\tpublic Bitmap loadImageSync(String uri, ImageSize targetImageSize, DisplayImageOptions options) {\n\t\tif (options == null) {\n\t\t\toptions = configuration.defaultDisplayImageOptions;\n\t\t}\n\t\toptions = new DisplayImageOptions.Builder().cloneFrom(options).syncLoading(true).build();\n\n\t\tSyncImageLoadingListener listener = new SyncImageLoadingListener();\n\t\tloadImage(uri, targetImageSize, options, listener);\n\t\treturn listener.getLoadedBitmap();\n\t}\n\n\t/**\n\t * Checks if ImageLoader's configuration was initialized\n\t *\n\t * @throws IllegalStateException if configuration wasn't initialized\n\t */\n\tprivate void checkConfiguration() {\n\t\tif (configuration == null) {\n\t\t\tthrow new IllegalStateException(ERROR_NOT_INIT);\n\t\t}\n\t}\n\n\t/** Sets a default loading listener for all display and loading tasks. */\n\tpublic void setDefaultLoadingListener(ImageLoadingListener listener) {\n\t\tdefaultListener = listener == null ? new SimpleImageLoadingListener() : listener;\n\t}\n\n\t/**\n\t * Returns memory cache\n\t *\n\t * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before\n\t */\n\tpublic MemoryCache getMemoryCache() {\n\t\tcheckConfiguration();\n\t\treturn configuration.memoryCache;\n\t}\n","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/core/ImageLoader.java#L595-L631","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()"],"exampleFix":"// before\npublic class MyActivity extends Activity {\n    protected void onCreate(Bundle b) {\n        ImageLoader.getInstance().displayImage(uri, imageView); // IllegalStateException\n    }\n}\n\n// after\npublic class App extends Application {\n    @Override public void onCreate() {\n        super.onCreate();\n        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));\n    }\n}","handlingStrategy":"validation","validationCode":"if (!ImageLoader.getInstance().isInited()) {\n    ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(context));\n}\nImageLoader.getInstance().displayImage(uri, imageView);","typeGuard":null,"tryCatchPattern":"try {\n    ImageLoader.getInstance().displayImage(uri, imageView);\n} catch (IllegalStateException e) {\n    ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(appContext));\n    ImageLoader.getInstance().displayImage(uri, imageView);\n}","preventionTips":["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"],"tags":["initialization","lifecycle","singleton","api-misuse"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}