nostra13/Android-Universal-Image-Loader · error · IllegalArgumentException

ImageLoader configuration can not be initialized with null

Error message

ImageLoader configuration can not be initialized with null

What it means

ImageLoader.init(ImageLoaderConfiguration) throws IllegalArgumentException(ERROR_INIT_CONFIG_WITH_NULL) when handed a null configuration. init() is the mandatory bootstrap: it creates the ImageLoaderEngine that all displayImage/loadImage calls depend on, so a null configuration would leave the singleton half-initialized. The class is a singleton; note that re-calling init with a non-null config after a successful init only logs a warning and does nothing until destroy().

Source

Thrown at library/src/main/java/com/nostra13/universalimageloader/core/ImageLoader.java:94

			}
		}
		return instance;
	}

	protected ImageLoader() {
	}

	/**
	 * Initializes ImageLoader instance with configuration.<br />
	 * If configurations was set before ( {@link #isInited()} == true) then this method does nothing.<br />
	 * To force initialization with new configuration you should {@linkplain #destroy() destroy ImageLoader} at first.
	 *
	 * @param configuration {@linkplain ImageLoaderConfiguration ImageLoader configuration}
	 * @throws IllegalArgumentException if <b>configuration</b> parameter is null
	 */
	public synchronized void init(ImageLoaderConfiguration configuration) {
		if (configuration == null) {
			throw new IllegalArgumentException(ERROR_INIT_CONFIG_WITH_NULL);
		}
		if (this.configuration == null) {
			L.d(LOG_INIT_CONFIG);
			engine = new ImageLoaderEngine(configuration);
			this.configuration = configuration;
		} else {
			L.w(WARNING_RE_INIT_CONFIG);
		}
	}

	/**
	 * Returns <b>true</b> - if ImageLoader {@linkplain #init(ImageLoaderConfiguration) is initialized with
	 * configuration}; <b>false</b> - otherwise
	 */
	public boolean isInited() {
		return configuration != null;
	}

View on GitHub (pinned to ba33ec64d0)

Solutions

  1. Always build a config inline: ImageLoader.getInstance().init(new ImageLoaderConfiguration.Builder(context).build())
  2. Make the config field non-null: build a minimal default config and only add extras conditionally
  3. Call init exactly once in Application.onCreate() before any displayImage call

Example fix

// before
ImageLoaderConfiguration cfg = null;
if (BuildConfig.DEBUG) cfg = new ImageLoaderConfiguration.Builder(this).build();
ImageLoader.getInstance().init(cfg); // throws in release

// after
ImageLoader.getInstance().init(new ImageLoaderConfiguration.Builder(this)
        .build());
Defensive patterns

Strategy: validation

Validate before calling

ImageLoaderConfiguration cfg = (config != null)
        ? config : ImageLoaderConfiguration.createDefault(context);
ImageLoader.getInstance().init(cfg);

Try / catch

try {
    ImageLoader.getInstance().init(config);
} catch (IllegalArgumentException e) {
    ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(context));
}

Prevention

When it happens

Trigger: ImageLoader.getInstance().init(null); init(config) where config is a field that a custom Application.onCreate never assigned; building the configuration conditionally and one branch returns null.

Common situations: Application subclass where ImageLoaderConfiguration.Builder is only built on some code paths (e.g. inside an if for debug builds); unit tests initializing ImageLoader without a config; refactoring that moved init() but lost the assignment.

Related errors


AI-assisted analysis of nostra13/Android-Universal-Image-Loader@ba33ec64d0 (2026-08-14). Data as JSON: /api/errors/3f109ab66ee38104. Report an issue: GitHub.