didi/DoKit · error · IllegalStateException
Error image already set.
Error message
Error image already set.
What it means
Thrown by RequestCreator.error(int) when an error Drawable was already set via error(Drawable). Picasso permits exactly one error image per request; combining the Drawable overload and the resource-id overload in one chain throws IllegalStateException.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java:149
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.");
}
this.errorDrawable = errorDrawable;
return this;
}View on GitHub (pinned to 626827cddb)
Solutions
- Keep only one error() call in the chain — either error(Drawable) or error(int)
- Make shared default-error logic conditional (only set a default if the caller did not set one)
- Start a new chain from picasso.load(...) with a single error configuration
Example fix
// before
picasso.load(url)
.error(errorDrawable)
.error(R.drawable.error) // throws "Error image already set."
.into(imageView);
// after
picasso.load(url)
.error(errorDrawable)
.into(imageView); Defensive patterns
Strategy: validation
Validate before calling
// Single source of truth for the error image
RequestCreator rc = picasso.load(url);
if (customErrorDrawable != null) {
rc.error(customErrorDrawable);
} else {
rc.error(R.drawable.default_error);
} Prevention
- Allow exactly one error() call per chain — enforce it in a wrapper method
- Do not layer default error images in base classes on top of call-site error images
- Prefer the resId overload for static defaults and the Drawable overload only when dynamic
When it happens
Trigger: Calling .error(drawable).error(R.drawable.err) on the same RequestCreator.
Common situations: Shared/base request builders that install a default error Drawable while call sites try to set their own error resId (or vice versa); refactoring from Drawable to resId without removing the old call.
Related errors
- Tag already set.
- Width must be positive number or 0.
- Height must be positive number or 0.
- Center crop can not be used after calling centerInside
- Center inside can not be used after calling centerCrop
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/bd6133915b92b102.
Report an issue: GitHub.