{"record":{"id":"58eb2f65fa5fe83c","repo":"didi/DoKit","slug":"fit-cannot-be-used-with-a-target","errorCode":null,"errorMessage":"Fit cannot be used with a Target.","messagePattern":"Fit cannot be used with a Target\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":521,"sourceCode":"     *   {@literal @}Override public void onPrepareLoad(Drawable placeHolderDrawable) {\n     *     frame.setBackgroundDrawable(placeHolderDrawable);\n     *   }\n     * }\n     * </pre></blockquote>\n     * <p>\n     * <em>Note:</em> This method keeps a weak reference to the {@link Target} instance and will be\n     * garbage collected if you do not keep a strong reference to it. To receive callbacks when an\n     * image is loaded use {@link #into(android.widget.ImageView, Callback)}.\n     */\n    public void into(Target target) {\n        long started = System.nanoTime();\n        checkMain();\n\n        if (target == null) {\n            throw new IllegalArgumentException(\"Target must not be null.\");\n        }\n        if (deferred) {\n            throw new IllegalStateException(\"Fit cannot be used with a Target.\");\n        }\n\n        if (!data.hasImage()) {\n            picasso.cancelRequest(target);\n            target.onPrepareLoad(setPlaceholder ? getPlaceholderDrawable() : null);\n            return;\n        }\n\n        Request request = createRequest(started);\n        String requestKey = createKey(request);\n\n        if (shouldReadFromMemoryCache(memoryPolicy)) {\n            Bitmap bitmap = picasso.quickMemoryCacheCheck(requestKey);\n            if (bitmap != null) {\n                picasso.cancelRequest(target);\n                target.onBitmapLoaded(bitmap, MEMORY);\n                return;\n            }","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L503-L539","documentation":"Thrown by RequestCreator.into(Target) when the chain called fit(). fit() works only with an ImageView, whose measured bounds are used to size the request after layout; a Target provides no measurement source, so Picasso rejects the combination with IllegalStateException.","triggerScenarios":"Calling picasso.load(url).fit().into(target), e.g. loading into a custom Target (Notification icon, custom View, Android Wear tile) while reusing a chain built for ImageViews.","commonSituations":"Shared loading helpers that always apply fit() being reused for Target-based loads (app widgets, notifications, custom views); migrating into(imageView) code to a Target without dropping fit().","solutions":["Remove fit() and size explicitly: .resize(dimW, dimH).centerInside().into(target)","Add a boolean or overload to the shared helper so fit() is applied only for ImageView loads","If the target ultimately feeds an ImageView, use into(imageView) instead of a Target"],"exampleFix":"// before\npicasso.load(url).fit().into(notificationTarget); // throws \"Fit cannot be used with a Target.\"\n\n// after\npicasso.load(url).resize(64, 64).centerCrop().into(notificationTarget);","handlingStrategy":"validation","validationCode":"// Target loads need explicit sizing; never fit()\npicasso.load(url)\n    .resize(iconSizePx, iconSizePx)\n    .centerCrop()\n    .into(target);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat fit() as ImageView-only; document it on shared loading helpers","Add an overload to shared helpers that skips fit() for Target/RemoteViews loads","Compute the destination dimensions yourself (e.g. notification icon size) when no ImageView exists"],"tags":["picasso","dokit","android","image-loading","fit","target"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}