didi/DoKit · error · IllegalArgumentException

At least one dimension has to be positive number.

Error message

At least one dimension has to be positive number.

What it means

Thrown by Request.Builder.resize(int, int) when both targetWidth and targetHeight are 0. Picasso uses 0 to mean 'derive this dimension from the other one to keep aspect ratio'; if both are 0 there is nothing to scale to, so the request is rejected.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java:307

     */
    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.
     */
    public Builder resize(int targetWidth, int targetHeight) {
      if (targetWidth < 0) {
        throw new IllegalArgumentException("Width must be positive number or 0.");
      }
      if (targetHeight < 0) {
        throw new IllegalArgumentException("Height must be positive number or 0.");
      }
      if (targetHeight == 0 && targetWidth == 0) {
        throw new IllegalArgumentException("At least one dimension has to be positive number.");
      }
      this.targetWidth = targetWidth;
      this.targetHeight = targetHeight;
      return this;
    }

    /** Clear the resize transformation, if any. This will also clear center crop/inside if set. */
    public Builder clearResize() {
      targetWidth = 0;
      targetHeight = 0;
      centerCrop = false;
      centerInside = false;
      return this;
    }

    /**
     * Crops an image inside of the bounds specified by {@link #resize(int, int)} rather than
     * distorting the aspect ratio. This cropping technique scales the image so that it fills the

View on GitHub (pinned to 626827cddb)

Solutions

  1. Ensure at least one dimension is a positive pixel value; check both before calling resize.
  2. Defer image loading until the view is measured (onLayoutChanged / ViewTreeObserver.OnGlobalLayoutListener) or use Picasso's fit() instead of resize().
  3. If only width is known, call resize(width, 0) — height is derived automatically.

Example fix

// before
picasso.load(url).resize(imageView.getWidth(), imageView.getHeight()).into(imageView); // both 0 pre-layout

// after
picasso.load(url).fit().centerInside().into(imageView); // sizes to the view at request time
Defensive patterns

Strategy: validation

Validate before calling

if (targetWidth > 0 || targetHeight > 0) {
  builder.resize(targetWidth, targetHeight);
} else {
  // defer until the view is measured, or use fit()
}

Prevention

When it happens

Trigger: Calling resize(0, 0), or resize(w, h) where both variables resolve to 0 at runtime (e.g., uninitialized fields, view not yet measured).

Common situations: Building the request before the target view is laid out (getWidth()/getHeight() both 0); passing two 'unspecified' sentinel zeros; copying sample code that hardcodes resize(0, 0).

Related errors


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