didi/DoKit · error · IllegalArgumentException

Error image may not be null.

Error message

Error image may not be null.

What it means

Thrown by RequestCreator.error(Drawable) when null is passed. Unlike placeholder(Drawable), which explicitly accepts null to clear an image, the error image cannot be null — Picasso needs something concrete to show on failure and throws IllegalArgumentException.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java:160

     * An error drawable to be used if the request image could not be loaded.
     */
    public RequestCreator error(int errorResId) {
        if (errorResId == 0) {
            throw new IllegalArgumentException("Error image resource invalid.");
        }
        if (errorDrawable != null) {
            throw new IllegalStateException("Error image already set.");
        }
        this.errorResId = errorResId;
        return this;
    }

    /**
     * An error drawable to be used if the request image could not be loaded.
     */
    public RequestCreator error(Drawable errorDrawable) {
        if (errorDrawable == null) {
            throw new IllegalArgumentException("Error image may not be null.");
        }
        if (errorResId != 0) {
            throw new IllegalStateException("Error image already set.");
        }
        this.errorDrawable = errorDrawable;
        return this;
    }

    /**
     * Assign a tag to this request. Tags are an easy way to logically associate
     * related requests that can be managed together e.g. paused, resumed,
     * or canceled.
     * <p>
     * You can either use simple {@link String} tags or objects that naturally
     * define the scope of your requests within your app such as a
     * {@link android.content.Context}, an {@link android.app.Activity}, or a
     * {@link android.app.Fragment}.
     *

View on GitHub (pinned to 626827cddb)

Solutions

  1. Pass a non-null Drawable, e.g. ContextCompat.getDrawable(context, R.drawable.err) after a null check
  2. Use error(int) with a valid resource id when you only have a resource reference
  3. If 'no error image' is intended, omit the error() call entirely
  4. In Kotlin, mark the parameter non-null or use errorResId.takeIf { it != 0 }?.let { builder.error(it) }

Example fix

// before
Drawable d = ContextCompat.getDrawable(context, R.drawable.err); // may be null
picasso.load(url).error(d).into(imageView); // throws "Error image may not be null."

// after
Drawable d = ContextCompat.getDrawable(context, R.drawable.err);
RequestCreator rc = picasso.load(url);
if (d != null) rc.error(d); else rc.error(R.drawable.err);
rc.into(imageView);
Defensive patterns

Strategy: validation

Validate before calling

Drawable d = ContextCompat.getDrawable(context, R.drawable.err);
if (d != null) {
    rc.error(d);
} else {
    rc.error(R.drawable.err);
}

Type guard

static Drawable requireErrorDrawable(Drawable d) {
    if (d == null) throw new IllegalArgumentException("Error drawable required");
    return d;
}

Prevention

When it happens

Trigger: Calling .error((Drawable) null) directly, or passing a field/getter that returned null (e.g. ContextCompat.getDrawable returning null was not checked, or a nullable field).

Common situations: Kotlin call sites passing a nullable Drawable without null handling; helper methods like getErrorDrawable() that can return null; copy-pasting the placeholder(null-to-clear) idiom onto error().

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/dac3cb62e073efd5. Report an issue: GitHub.