didi/DoKit · error · IllegalArgumentException
Image resource ID may not be 0.
Error message
Image resource ID may not be 0.
What it means
Request.Builder.setResourceId() throws IllegalArgumentException when resourceId is 0. Resource ID 0 in Android means 'no resource', so a Request pointing at resource 0 is invalid; setting a URI (which clears resourceId to 0) is the supported way to express 'no resource'. Fail-fast guard.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java:279
* This will clear an image resource ID if one is set.
*/
public Builder setUri(Uri uri) {
if (uri == null) {
throw new IllegalArgumentException("Image URI may not be null.");
}
this.uri = uri;
this.resourceId = 0;
return this;
}
/**
* Set the target image resource ID.
* <p>
* This will clear an image Uri if one is set.
*/
public Builder setResourceId(int resourceId) {
if (resourceId == 0) {
throw new IllegalArgumentException("Image resource ID may not be 0.");
}
this.resourceId = resourceId;
this.uri = null;
return this;
}
/**
* Set the stable key to be used instead of the URI or resource ID when caching.
* Two requests with the same value are considered to be for the same resource.
*/
public Builder stableKey(String stableKey) {
this.stableKey = stableKey;
return this;
}
/**
* Resize the image to the specified size in pixels.
* Use 0 as desired dimension to resize keeping aspect ratio.View on GitHub (pinned to 626827cddb)
Solutions
- Resolve the resource first and fall back to a known-good drawable when getIdentifier() returns 0
- Validate server/remote resource names against a local map of valid IDs before building the request
- Use setUri(Uri) when the image is not a local resource
Example fix
// before int id = resources.getIdentifier(name, "drawable", pkg); // 0 when name missing requestBuilder.setResourceId(id); // IllegalArgumentException // after int id = resources.getIdentifier(name, "drawable", pkg); if (id == 0) id = R.drawable.fallback; requestBuilder.setResourceId(id);
Defensive patterns
Strategy: validation
Validate before calling
int id = resources.getIdentifier(name, "drawable", packageName);
if (id == 0) { id = R.drawable.image_fallback; } // or use setUri(remoteUrl)
requestBuilder.setResourceId(id); Type guard
boolean isValidResourceId(int id) { return id != 0; } Prevention
- Never pass raw getIdentifier() results to setResourceId; check for 0 first
- Map server-driven names to a compile-time resource map so misses are impossible
When it happens
Trigger: Calling setResourceId(0), e.g. passing an unresolvable or unresolved resource identifier such as 0 returned from Resources.getIdentifier() when the name was not found, or a default field value.
Common situations: Dynamically resolving icons by name with getIdentifier() which returns 0 on miss; server-driven resource names that do not exist in the app; passing a default int field that was never set.
Related errors
- Placeholder image resource invalid.
- Path must not be empty.
- Resource ID must not be zero.
- uri == null
- path == null
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/a29959f96c817bc1.
Report an issue: GitHub.