{"record":{"id":"bd6133915b92b102","repo":"didi/DoKit","slug":"error-image-already-set","errorCode":null,"errorMessage":"Error image already set.","messagePattern":"Error image already set\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":149,"sourceCode":"        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        }\n        this.errorDrawable = errorDrawable;\n        return this;\n    }","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L131-L167","documentation":"Thrown by RequestCreator.error(int) when an error Drawable was already set via error(Drawable). Picasso permits exactly one error image per request; combining the Drawable overload and the resource-id overload in one chain throws IllegalStateException.","triggerScenarios":"Calling .error(drawable).error(R.drawable.err) on the same RequestCreator.","commonSituations":"Shared/base request builders that install a default error Drawable while call sites try to set their own error resId (or vice versa); refactoring from Drawable to resId without removing the old call.","solutions":["Keep only one error() call in the chain — either error(Drawable) or error(int)","Make shared default-error logic conditional (only set a default if the caller did not set one)","Start a new chain from picasso.load(...) with a single error configuration"],"exampleFix":"// before\npicasso.load(url)\n    .error(errorDrawable)\n    .error(R.drawable.error) // throws \"Error image already set.\"\n    .into(imageView);\n\n// after\npicasso.load(url)\n    .error(errorDrawable)\n    .into(imageView);","handlingStrategy":"validation","validationCode":"// Single source of truth for the error image\nRequestCreator rc = picasso.load(url);\nif (customErrorDrawable != null) {\n    rc.error(customErrorDrawable);\n} else {\n    rc.error(R.drawable.default_error);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allow exactly one error() call per chain — enforce it in a wrapper method","Do not layer default error images in base classes on top of call-site error images","Prefer the resId overload for static defaults and the Drawable overload only when dynamic"],"tags":["picasso","dokit","android","image-loading","builder","api-misuse"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}