didi/DoKit · error · IllegalStateException
Center crop requires calling resize with positive width and
Error message
Center crop requires calling resize with positive width and height.
What it means
Thrown by Request.Builder.build() when centerCrop was set but no resize target exists (both targetWidth and targetHeight are 0). Center-crop needs explicit bounds to know what to fill and where to crop; without them the operation is undefined.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java:460
* Custom transformations will always be run after the built-in transformations.
*/
public Builder transform(List<? extends Transformation> transformations) {
if (transformations == null) {
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
- Add .resize(width, height) with at least one positive dimension before .centerCrop().
- If sizing to an ImageView, use .fit().centerCrop() instead of explicit resize.
- Check for clearResize() calls in shared builders that invalidate the resize target.
Example fix
// before picasso.load(url).centerCrop().into(imageView); // after picasso.load(url).fit().centerCrop().into(imageView); // or .resize(400, 400).centerCrop()
Defensive patterns
Strategy: validation
Validate before calling
if (targetWidth > 0 || targetHeight > 0) { builder.resize(w, h).centerCrop(); } else { builder.fit().centerCrop(); } Prevention
- Pair every centerCrop() with a resize() or use fit().
- clearResize() invalidates centerCrop; clear both if clearing.
When it happens
Trigger: Chaining .centerCrop() with no .resize(w, h) (or after clearResize()) and then building/into().
Common situations: Copy-pasting a chain but dropping the resize call; calling clearResize() in shared code while keeping centerCrop; expecting centerCrop() alone to size to the view (that is what fit() is for).
Related errors
- onlyScaleDown can not be applied without resize
- Center inside requires calling resize with positive width an
- 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/da6eda1e530b169f.
Report an issue: GitHub.