didi/DoKit · error · IllegalStateException
Center inside requires calling resize with positive width an
Error message
Center inside requires calling resize with positive width and height.
What it means
Thrown by Request.Builder.build() when centerInside was set but no resize target exists (targetWidth == 0 && targetHeight == 0). Center-inside scales an image down to fit inside bounds; with no bounds the transformation has nothing to fit into, so build() rejects it.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java:464
throw new IllegalArgumentException("Transformation list must not be null.");
}
for (int i = 0, size = transformations.size(); i < size; i++) {
transform(transformations.get(i));
}
return this;
}
/** Create the immutable {@link Request} object. */
public Request build() {
if (centerInside && centerCrop) {
throw new IllegalStateException("Center crop and center inside can not be used together.");
}
if (centerCrop && (targetWidth == 0 && targetHeight == 0)) {
throw new IllegalStateException(
"Center crop requires calling resize with positive width and height.");
}
if (centerInside && (targetWidth == 0 && targetHeight == 0)) {
throw new IllegalStateException(
"Center inside requires calling resize with positive width and height.");
}
if (priority == null) {
priority = Priority.NORMAL;
}
return new Request(uri, resourceId, stableKey, transformations, targetWidth, targetHeight,
centerCrop, centerInside, onlyScaleDown, rotationDegrees, rotationPivotX, rotationPivotY,
hasRotationPivot, config, priority);
}
}
}
View on GitHub (pinned to 626827cddb)
Solutions
- Call .resize(w, h) with at least one positive dimension before .centerInside().
- Use .fit().centerInside() to size to the view at request time.
- Log/validate dimensions at request-build time when they come from view measurements.
Example fix
// before picasso.load(url).centerInside().into(imageView); // after picasso.load(url).fit().centerInside().into(imageView); // or .resize(600, 400).centerInside()
Defensive patterns
Strategy: validation
Validate before calling
if (targetWidth > 0 || targetHeight > 0) { builder.resize(w, h).centerInside(); } else { builder.fit().centerInside(); } Prevention
- Pair every centerInside() with resize() or fit().
- Load after layout when dimensions come from a view.
When it happens
Trigger: Chaining .centerInside() with no .resize(w, h) (or after clearResize()) and then building/into().
Common situations: Request built before the target view is measured so resize values ended up 0/omitted; removing a resize call during refactoring while keeping centerInside; assuming centerInside() alone constrains the image.
Related errors
- onlyScaleDown can not be applied without resize
- Center crop requires calling resize with positive width and
- Width must be positive number or 0.
- Height must be positive number or 0.
- Center crop can not be used after calling centerInside
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/0d035aafb8bf1e5f.
Report an issue: GitHub.