{"record":{"id":"91acbd3f7730a69f","repo":"didi/DoKit","slug":"placeholder-image-resource-invalid","errorCode":null,"errorMessage":"Placeholder image resource invalid.","messagePattern":"Placeholder image resource invalid\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":113,"sourceCode":"        }\n        if (placeholderDrawable != null) {\n            throw new IllegalStateException(\"Placeholder image already set.\");\n        }\n        setPlaceholder = false;\n        return this;\n    }\n\n    /**\n     * A placeholder drawable to be used while the image is being loaded. If the requested image is\n     * not immediately available in the memory cache then this resource will be set on the target\n     * {@link ImageView}.\n     */\n    public RequestCreator placeholder(int placeholderResId) {\n        if (!setPlaceholder) {\n            throw new IllegalStateException(\"Already explicitly declared as no placeholder.\");\n        }\n        if (placeholderResId == 0) {\n            throw new IllegalArgumentException(\"Placeholder image resource invalid.\");\n        }\n        if (placeholderDrawable != null) {\n            throw new IllegalStateException(\"Placeholder image already set.\");\n        }\n        this.placeholderResId = placeholderResId;\n        return this;\n    }\n\n    /**\n     * A placeholder drawable to be used while the image is being loaded. If the requested image is\n     * not immediately available in the memory cache then this resource will be set on the target\n     * {@link ImageView}.\n     * <p>\n     * If you are not using a placeholder image but want to clear an existing image (such as when\n     * used in an {@link android.widget.Adapter adapter}), pass in {@code null}.\n     */\n    public RequestCreator placeholder(Drawable placeholderDrawable) {\n        if (!setPlaceholder) {","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L95-L131","documentation":"Thrown by RequestCreator.placeholder(int) when the passed resource id is 0. In Android, 0 means 'no resource', so it cannot identify a placeholder drawable; Picasso rejects it rather than silently skipping the placeholder.","triggerScenarios":"Calling placeholder(0), or placeholder(phResId) where the variable is 0 (unset attribute, default parameter value, missing typed-array entry).","commonSituations":"Reading a custom XML styleable attribute that was not set (typed array returns 0); Java default parameter of 0 flowing through; Kotlin nullable Int mapped to 0 with '?: 0'.","solutions":["Only call placeholder(resId) when resId != 0; guard the call.","In XML parsing, check typedArray.getResourceId(...) != 0 before using it.","In Kotlin, model optional resource ids as Int? and skip the call when null."],"exampleFix":"// before\nint ph = a.getResourceId(R.styleable.MyView_placeholder, 0);\npicasso.load(url).placeholder(ph).into(view); // throws when attr unset\n\n// after\nint ph = a.getResourceId(R.styleable.MyView_placeholder, 0);\nRequestCreator c = picasso.load(url);\nif (ph != 0) c.placeholder(ph);\nc.into(view);","handlingStrategy":"validation","validationCode":"RequestCreator c = picasso.load(url);\nif (placeholderResId != 0) c.placeholder(placeholderResId);\nc.into(view);","typeGuard":"static boolean isValidResId(int resId) { return resId != 0; }","tryCatchPattern":null,"preventionTips":["Treat resource id 0 as 'unset' and skip the placeholder call.","Check typed-array values with getResourceId(...) != 0 before use.","In Kotlin use Int? for optional resource ids instead of defaulting to 0."],"tags":["android","picasso","resources","validation","placeholder"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}