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

displayer can't be null

Error message

displayer can't be null

What it means

DisplayImageOptions.Builder.displayer(BitmapDisplayer) rejects a null displayer because every load task ends by handing its bitmap to the displayer on the UI thread (DefaultConfigurationFactory.createBitmapDisplayer() supplies SimpleBitmapDisplayer by default). A null displayer would make images silently never appear; failing fast in the builder surfaces the mistake where it is made.

Source

Thrown at library/src/main/java/com/nostra13/universalimageloader/core/DisplayImageOptions.java:439

			return this;
		}

		/**
		 * Sets bitmap processor which will be process bitmaps before they will be displayed in
		 * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware image aware view} but
		 * after they'll have been saved in memory cache.
		 */
		public Builder postProcessor(BitmapProcessor postProcessor) {
			this.postProcessor = postProcessor;
			return this;
		}

		/**
		 * Sets custom {@link BitmapDisplayer displayer} for image loading task. Default value -
		 * {@link DefaultConfigurationFactory#createBitmapDisplayer()}
		 */
		public Builder displayer(BitmapDisplayer displayer) {
			if (displayer == null) throw new IllegalArgumentException("displayer can't be null");
			this.displayer = displayer;
			return this;
		}

		Builder syncLoading(boolean isSyncLoading) {
			this.isSyncLoading = isSyncLoading;
			return this;
		}

		/**
		 * Sets custom {@linkplain Handler handler} for displaying images and firing {@linkplain ImageLoadingListener
		 * listener} events.
		 */
		public Builder handler(Handler handler) {
			this.handler = handler;
			return this;
		}

View on GitHub (pinned to ba33ec64d0)

Solutions

  1. Use SimpleBitmapDisplayer.INSTANCE (or new SimpleBitmapDisplayer()) for the no-op branch
  2. For simple fade-in use new FadeInBitmapDisplayer(300) instead of null
  3. Make injected displayer fields non-optional with a default provider

Example fix

// before
builder.displayer(animate ? new FadeInBitmapDisplayer(300) : null); // throws when !animate

// after
builder.displayer(animate
        ? new FadeInBitmapDisplayer(300)
        : new SimpleBitmapDisplayer());
Defensive patterns

Strategy: validation

Validate before calling

BitmapDisplayer d = (displayer != null)
        ? displayer : new SimpleBitmapDisplayer();
options.displayer(d);

Type guard

static boolean isUsableDisplayer(BitmapDisplayer d) {
    return d != null;
}

Prevention

When it happens

Trigger: Calling .displayer(null) when wiring a custom animation/display strategy; conditional code like animate ? new FadeInBitmapDisplayer(300) : null; a DI framework injecting an unset optional displayer.

Common situations: Feature-flagged animations ('animate or no displayer'); Dagger/Spring-injected fields defaulting to null; refactoring where a custom displayer class was deleted but the wiring left the call.

Related errors


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