{"record":{"id":"5f7ef6725129c956","repo":"didi/DoKit","slug":"error-image-resource-invalid","errorCode":null,"errorMessage":"Error image resource invalid.","messagePattern":"Error image resource invalid\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":146,"sourceCode":"     * used in an {@link android.widget.Adapter adapter}), pass in {@code null}.\n     */\n    public RequestCreator placeholder(Drawable placeholderDrawable) {\n        if (!setPlaceholder) {\n            throw new IllegalStateException(\"Already explicitly declared as no placeholder.\");\n        }\n        if (placeholderResId != 0) {\n            throw new IllegalStateException(\"Placeholder image already set.\");\n        }\n        this.placeholderDrawable = placeholderDrawable;\n        return this;\n    }\n\n    /**\n     * An error drawable to be used if the request image could not be loaded.\n     */\n    public RequestCreator error(int errorResId) {\n        if (errorResId == 0) {\n            throw new IllegalArgumentException(\"Error image resource invalid.\");\n        }\n        if (errorDrawable != null) {\n            throw new IllegalStateException(\"Error image already set.\");\n        }\n        this.errorResId = errorResId;\n        return this;\n    }\n\n    /**\n     * An error drawable to be used if the request image could not be loaded.\n     */\n    public RequestCreator error(Drawable errorDrawable) {\n        if (errorDrawable == null) {\n            throw new IllegalArgumentException(\"Error image may not be null.\");\n        }\n        if (errorResId != 0) {\n            throw new IllegalStateException(\"Error image already set.\");\n        }","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L128-L164","documentation":"Thrown by RequestCreator.error(int) when the passed resource id is 0. In Android, 0 is not a valid resource reference, so Picasso treats it as an unset/invalid argument and throws IllegalArgumentException immediately rather than silently loading nothing on failure.","triggerScenarios":"Calling .error(0), or passing a variable/attribute that resolved to 0 (e.g. an unset styled attribute or a default constant) into error(int).","commonSituations":"Reading a placeholder/error drawable reference from XML styled attributes (obtainStyledAttributes) where the attribute was omitted and returned 0; passing android.R.color.transparent or an un-initialized field; code migrated from a library where 0 meant 'no error image'.","solutions":["Pass a real drawable resource id (nonzero) to error(int)","If 'no error image' is intended, simply omit the error() call instead of passing 0","If you only have a Drawable, use error(Drawable) with a non-null value","Guard before the call: if (errorResId != 0) builder.error(errorResId);"],"exampleFix":"// before\nint errorResId = a.getResourceId(R.styleable.MyView_errorSrc, 0);\npicasso.load(url).error(errorResId).into(imageView); // throws when attribute missing\n\n// after\nint errorResId = a.getResourceId(R.styleable.MyView_errorSrc, 0);\nRequestCreator rc = picasso.load(url);\nif (errorResId != 0) rc.error(errorResId);\nrc.into(imageView);","handlingStrategy":"validation","validationCode":"RequestCreator rc = picasso.load(url);\nif (errorResId != 0) {\n    rc.error(errorResId);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat 0 as 'unset' for every Android resource id and guard before passing it","When reading styled attributes, always check the default/return value for 0","Do not pass constants like android.R.color.transparent as error images"],"tags":["picasso","dokit","android","image-loading","resource-id","validation"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}