didi/DoKit · error · IllegalStateException

Placeholder resource already set.

Error message

Placeholder resource already set.

What it means

Thrown by RequestCreator.noPlaceholder() when a placeholder resource id was already set via placeholder(int). noPlaceholder() is an exclusive alternative to any placeholder, so Picasso rejects mixing them on the same creator.

Source

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

        this.picasso = picasso;
        this.data = new Request.Builder(uri, resourceId, picasso.defaultBitmapConfig);
    }

    RequestCreator() {
        this.picasso = null;
        this.data = new Request.Builder(null, 0, null);
    }

    /**
     * Explicitly opt-out to having a placeholder set when calling {@code into}.
     * <p>
     * By default, Picasso will either set a supplied placeholder or clear the target
     * {@link ImageView} in order to ensure behavior in situations where views are recycled. This
     * method will prevent that behavior and retain any already set image.
     */
    public RequestCreator noPlaceholder() {
        if (placeholderResId != 0) {
            throw new IllegalStateException("Placeholder resource already set.");
        }
        if (placeholderDrawable != null) {
            throw new IllegalStateException("Placeholder image already set.");
        }
        setPlaceholder = false;
        return this;
    }

    /**
     * A placeholder drawable to be used while the image is being loaded. If the requested image is
     * not immediately available in the memory cache then this resource will be set on the target
     * {@link ImageView}.
     */
    public RequestCreator placeholder(int placeholderResId) {
        if (!setPlaceholder) {
            throw new IllegalStateException("Already explicitly declared as no placeholder.");
        }
        if (placeholderResId == 0) {

View on GitHub (pinned to 626827cddb)

Solutions

  1. Choose either a placeholder or noPlaceholder() per request — never both.
  2. Make placeholder presence a single decision point (parameter of your loader helper).
  3. If a default placeholder was applied, build a fresh request without it instead of calling noPlaceholder().

Example fix

// before
RequestCreator c = picasso.load(url).placeholder(R.drawable.ph);
c.noPlaceholder(); // throws

// after
RequestCreator c = picasso.load(url).placeholder(R.drawable.ph); // keep placeholder
// or
RequestCreator c = picasso.load(url).noPlaceholder(); // no placeholder at all
Defensive patterns

Strategy: validation

Validate before calling

// Single decision point in your helper
RequestCreator c = picasso.load(url);
if (placeholderResId != 0) c.placeholder(placeholderResId); else c.noPlaceholder();

Prevention

When it happens

Trigger: Chaining .placeholder(R.drawable.ph).noPlaceholder() (or calling them in either order on the same RequestCreator).

Common situations: Shared helper applying a default placeholder, then request-specific code adding noPlaceholder(); copy-paste of two different samples into one chain; conditional logic where both branches execute.

Related errors


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