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

Wrong arguments were passed to displayImage() method (ImageV

Error message

Wrong arguments were passed to displayImage() method (ImageView reference must not be null)

What it means

The full displayImage(uri, imageAware, options, targetSize, listener, progressListener) overload rejects a null imageAware (ImageView wrapper) with IllegalArgumentException(ERROR_WRONG_ARGUMENTS). Every internal variant (displayImage(String, ImageView), displayImage(String, ImageAware, ...)) delegates here, so the ImageView/ImageAware argument must be non-null in all of them. Loading into a null view is almost always a lifecycle bug (view already destroyed), so it fails fast.

Source

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

	 *                         decoding and displaying. If <b>null</b> - default display image options
	 *                         {@linkplain ImageLoaderConfiguration.Builder#defaultDisplayImageOptions(DisplayImageOptions)
	 *                         from configuration} will be used.
	 * @param targetSize       {@linkplain ImageSize} Image target size. If <b>null</b> - size will depend on the view
	 * @param listener         {@linkplain ImageLoadingListener Listener} for image loading process. Listener fires
	 *                         events on UI thread if this method is called on UI thread.
	 * @param progressListener {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
	 *                         Listener} for image loading progress. Listener fires events on UI thread if this method
	 *                         is called on UI thread. Caching on disk should be enabled in
	 *                         {@linkplain com.nostra13.universalimageloader.core.DisplayImageOptions options} to make
	 *                         this listener work.
	 * @throws IllegalStateException    if {@link #init(ImageLoaderConfiguration)} method wasn't called before
	 * @throws IllegalArgumentException if passed <b>imageAware</b> is null
	 */
	public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options,
			ImageSize targetSize, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
		checkConfiguration();
		if (imageAware == null) {
			throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
		}
		if (listener == null) {
			listener = defaultListener;
		}
		if (options == null) {
			options = configuration.defaultDisplayImageOptions;
		}

		if (TextUtils.isEmpty(uri)) {
			engine.cancelDisplayTaskFor(imageAware);
			listener.onLoadingStarted(uri, imageAware.getWrappedView());
			if (options.shouldShowImageForEmptyUri()) {
				imageAware.setImageDrawable(options.getImageForEmptyUri(configuration.resources));
			} else {
				imageAware.setImageDrawable(null);
			}
			listener.onLoadingComplete(uri, imageAware.getWrappedView(), null);
			return;

View on GitHub (pinned to ba33ec64d0)

Solutions

  1. Null-check views captured by async callbacks before calling displayImage: if (imageView != null) ...
  2. Clear pending callbacks or use the library's own task cancellation (ImageLoader.cancelDisplayTask(imageAware)) in onDestroyView
  3. Ensure displayImage is called after setContentView/onViewCreated, not in onCreate before inflation

Example fix

// before
someApi.fetch(url, new Callback() {
    public void done(String uri) {
        ImageLoader.getInstance().displayImage(uri, holder.imageView); // null after recycle
    }
});

// after
someApi.fetch(url, new Callback() {
    public void done(String uri) {
        ImageView iv = holder.imageView;
        if (iv != null) ImageLoader.getInstance().displayImage(uri, iv);
    }
});
Defensive patterns

Strategy: type-guard

Validate before calling

if (imageAware != null && imageAware.getWrappedView() != null) {
    ImageLoader.getInstance().displayImage(uri, imageAware, options);
}

Type guard

static boolean isDisplayable(ImageAware aware) {
    return aware != null && aware.getWrappedView() != null;
}

Prevention

When it happens

Trigger: ImageLoader.getInstance().displayImage(uri, (ImageView) null); passing an ImageAware whose wrapped view was nulled by onDestroy; async callbacks (e.g. listener futures, event bus handlers) capturing a view reference after the fragment's view was destroyed and set to null.

Common situations: Fragment/adapter async completion where the view field was cleared in onDestroyView; findViewById returning null before the layout was inflated; recycled holders whose ImageView field was reset; Kotlin code with a nullable ImageView passed straight through.

Related errors


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