{"record":{"id":"14acf6fd6a6b1526","repo":"didi/DoKit","slug":"resource-id-must-not-be-zero","errorCode":null,"errorMessage":"Resource ID must not be zero.","messagePattern":"Resource ID must not be zero\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/DokitPicasso.java","lineNumber":332,"sourceCode":"   * @see #load(int)\n   */\n  public RequestCreator load(File file) {\n    if (file == null) {\n      return new RequestCreator(this, null, 0);\n    }\n    return load(Uri.fromFile(file));\n  }\n\n  /**\n   * Start an image request using the specified drawable resource ID.\n   *\n   * @see #load(Uri)\n   * @see #load(String)\n   * @see #load(File)\n   */\n  public RequestCreator load(int resourceId) {\n    if (resourceId == 0) {\n      throw new IllegalArgumentException(\"Resource ID must not be zero.\");\n    }\n    return new RequestCreator(this, null, resourceId);\n  }\n\n  /**\n   * Invalidate all memory cached images for the specified {@code uri}.\n   *\n   * @see #invalidate(String)\n   * @see #invalidate(File)\n   */\n  public void invalidate(Uri uri) {\n    if (uri == null) {\n      throw new IllegalArgumentException(\"uri == null\");\n    }\n    cache.clearKeyUri(uri.toString());\n  }\n\n  /**","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/DokitPicasso.java#L314-L350","documentation":"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.","triggerScenarios":"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.","commonSituations":"Intent extras with a missing resource id; feature-flavor code referencing a drawable that exists only in another flavor; reflection-fed resource ids.","solutions":["Guard: if (resId != 0) load(resId) else load(placeholder drawable or null)","Verify the resource exists in the active build variant (drawable in the right flavor/res bucket)","Check ProGuard/R8 keep rules are not stripping resource fields referenced dynamically","When receiving ids from Intents, use getIntent().getIntExtra(key, -1) and validate against 0/-1"],"exampleFix":"// before\nDokitPicasso.with(context).load(intent.getIntExtra(\"icon\", 0)).into(view);\n\n// after\nint resId = intent.getIntExtra(\"icon\", 0);\nRequestCreator rq = resId != 0\n    ? DokitPicasso.with(context).load(resId)\n    : DokitPicasso.with(context).load(R.drawable.default_icon);\nrq.into(view);","handlingStrategy":"validation","validationCode":"if (resId != 0) {\n  picasso.load(resId).into(view);\n} else {\n  view.setImageResource(R.drawable.default_icon);\n}","typeGuard":null,"tryCatchPattern":"try {\n  picasso.load(resId).into(view);\n} catch (IllegalArgumentException e) {\n  if (\"Resource ID must not be zero.\".equals(e.getMessage())) {\n    view.setImageResource(R.drawable.default_icon);\n  } else throw e;\n}","preventionTips":["Check resId != 0 before load(resId) — 0 means 'unset' in Android resource handling","Use getIntExtra(key, -1) and validate both 0 and -1","Keep resource references compile-time (R.drawable.x) so missing variants fail at build, not runtime"],"tags":["android","picasso","resource","validation"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}