didi/DoKit · error · IllegalArgumentException

Resource ID must not be zero.

Error message

Resource ID must not be zero.

What it means

load(int resourceId) rejects 0 because Android resource IDs are never 0 for real drawables — 0 is the default value of an unset resource field, and passing it would later fail with a cryptic Resources.NotFoundException. Picasso fails fast with IllegalArgumentException('Resource ID must not be zero.') at the API boundary. Note load(0) is NOT treated like load(null)/load("") (which are allowed no-ops); an int argument must be a real resource.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/DokitPicasso.java:332

   * @see #load(int)
   */
  public RequestCreator load(File file) {
    if (file == null) {
      return new RequestCreator(this, null, 0);
    }
    return load(Uri.fromFile(file));
  }

  /**
   * Start an image request using the specified drawable resource ID.
   *
   * @see #load(Uri)
   * @see #load(String)
   * @see #load(File)
   */
  public RequestCreator load(int resourceId) {
    if (resourceId == 0) {
      throw new IllegalArgumentException("Resource ID must not be zero.");
    }
    return new RequestCreator(this, null, resourceId);
  }

  /**
   * Invalidate all memory cached images for the specified {@code uri}.
   *
   * @see #invalidate(String)
   * @see #invalidate(File)
   */
  public void invalidate(Uri uri) {
    if (uri == null) {
      throw new IllegalArgumentException("uri == null");
    }
    cache.clearKeyUri(uri.toString());
  }

  /**

View on GitHub (pinned to 626827cddb)

Solutions

  1. Guard: if (resId != 0) load(resId) else load(placeholder drawable or null)
  2. Verify the resource exists in the active build variant (drawable in the right flavor/res bucket)
  3. Check ProGuard/R8 keep rules are not stripping resource fields referenced dynamically
  4. When receiving ids from Intents, use getIntent().getIntExtra(key, -1) and validate against 0/-1

Example fix

// before
DokitPicasso.with(context).load(intent.getIntExtra("icon", 0)).into(view);

// after
int resId = intent.getIntExtra("icon", 0);
RequestCreator rq = resId != 0
    ? DokitPicasso.with(context).load(resId)
    : DokitPicasso.with(context).load(R.drawable.default_icon);
rq.into(view);
Defensive patterns

Strategy: validation

Validate before calling

if (resId != 0) {
  picasso.load(resId).into(view);
} else {
  view.setImageResource(R.drawable.default_icon);
}

Try / catch

try {
  picasso.load(resId).into(view);
} catch (IllegalArgumentException e) {
  if ("Resource ID must not be zero.".equals(e.getMessage())) {
    view.setImageResource(R.drawable.default_icon);
  } else throw e;
}

Prevention

When it happens

Trigger: load(R.drawable.foo) where R.drawable.foo resolves to 0 — typically because the symbol was inlined from another package/build variant, the field was removed by ProGuard/R8 renaming, or the caller passes bundle.getInt("res", 0) default; passing an unparcelled/invalidated extra.

Common situations: Intent extras with a missing resource id; feature-flavor code referencing a drawable that exists only in another flavor; reflection-fed resource ids.

Related errors


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