didi/DoKit · error · IllegalArgumentException

Error image resource invalid.

Error message

Error image resource invalid.

What it means

Thrown by RequestCreator.error(int) when the passed resource id is 0. In Android, 0 is not a valid resource reference, so Picasso treats it as an unset/invalid argument and throws IllegalArgumentException immediately rather than silently loading nothing on failure.

Source

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

     * used in an {@link android.widget.Adapter adapter}), pass in {@code null}.
     */
    public RequestCreator placeholder(Drawable placeholderDrawable) {
        if (!setPlaceholder) {
            throw new IllegalStateException("Already explicitly declared as no placeholder.");
        }
        if (placeholderResId != 0) {
            throw new IllegalStateException("Placeholder image already set.");
        }
        this.placeholderDrawable = placeholderDrawable;
        return this;
    }

    /**
     * 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.");
        }

View on GitHub (pinned to 626827cddb)

Solutions

  1. Pass a real drawable resource id (nonzero) to error(int)
  2. If 'no error image' is intended, simply omit the error() call instead of passing 0
  3. If you only have a Drawable, use error(Drawable) with a non-null value
  4. Guard before the call: if (errorResId != 0) builder.error(errorResId);

Example fix

// before
int errorResId = a.getResourceId(R.styleable.MyView_errorSrc, 0);
picasso.load(url).error(errorResId).into(imageView); // throws when attribute missing

// after
int errorResId = a.getResourceId(R.styleable.MyView_errorSrc, 0);
RequestCreator rc = picasso.load(url);
if (errorResId != 0) rc.error(errorResId);
rc.into(imageView);
Defensive patterns

Strategy: validation

Validate before calling

RequestCreator rc = picasso.load(url);
if (errorResId != 0) {
    rc.error(errorResId);
}

Prevention

When it happens

Trigger: Calling .error(0), or passing a variable/attribute that resolved to 0 (e.g. an unset styled attribute or a default constant) into error(int).

Common situations: Reading a placeholder/error drawable reference from XML styled attributes (obtainStyledAttributes) where the attribute was omitted and returned 0; passing android.R.color.transparent or an un-initialized field; code migrated from a library where 0 meant 'no error image'.

Related errors


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