{"record":{"id":"3125cc69114b9570","repo":"didi/DoKit","slug":"fit-cannot-be-used-with-remoteviews","errorCode":null,"errorMessage":"Fit cannot be used with RemoteViews.","messagePattern":"Fit cannot be used with RemoteViews\\.","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":565,"sourceCode":"        picasso.enqueueAndSubmit(action);\n    }\n\n    /**\n     * Asynchronously fulfills the request into the specified {@link RemoteViews} object with the\n     * given {@code viewId}. This is used for loading bitmaps into a {@link Notification}.\n     */\n    public void into(RemoteViews remoteViews, int viewId, int notificationId,\n                     Notification notification) {\n        long started = System.nanoTime();\n\n        if (remoteViews == null) {\n            throw new IllegalArgumentException(\"RemoteViews must not be null.\");\n        }\n        if (notification == null) {\n            throw new IllegalArgumentException(\"Notification must not be null.\");\n        }\n        if (deferred) {\n            throw new IllegalStateException(\"Fit cannot be used with RemoteViews.\");\n        }\n        if (placeholderDrawable != null || placeholderResId != 0 || errorDrawable != null) {\n            throw new IllegalArgumentException(\n                    \"Cannot use placeholder or error drawables with remote views.\");\n        }\n\n        Request request = createRequest(started);\n        String key = createKey(request, new StringBuilder()); // Non-main thread needs own builder.\n\n        RemoteViewsAction action =\n                new NotificationAction(picasso, request, remoteViews, viewId, notificationId, notification,\n                        memoryPolicy, networkPolicy, key, tag, errorResId);\n\n        performRemoteViewInto(action);\n    }\n\n    /**\n     * Asynchronously fulfills the request into the specified {@link RemoteViews} object with the","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L547-L583","documentation":"Thrown by RequestCreator.into(RemoteViews, int, int, Notification) when the request was built with fit(). fit() only defers size measurement to an ImageView's layout pass; a RemoteViews notification has no measurable view in this process, so a deferred resize can never be resolved. The library rejects the combination up front rather than silently loading an unsized image.","triggerScenarios":"Chaining .fit() followed by into(remoteViews, viewId, notificationId, notification) — fit() sets the internal deferred flag, and into(...) for notifications throws IllegalStateException when deferred is true.","commonSituations":"Copying an ImageView load call (which used fit()) into a notification-icon loader; refactoring a UI preview into a notification without removing fit(); adding RemoteViews support to code that previously loaded into an ImageView.","solutions":["Remove the .fit() call from the request builder used for the notification RemoteViews load.","If a specific icon size is required, use .resize(w, h) or .resizeDimen(...) instead of fit(), since resize is compatible with RemoteViews.","Keep two separate builder chains: one with fit() for ImageView targets, one without for RemoteViews/notification targets."],"exampleFix":"// before\npicasso.load(url).fit().into(remoteViews, R.id.icon, notifId, notification);\n\n// after\npicasso.load(url).resize(smallIconSize, smallIconSize).into(remoteViews, R.id.icon, notifId, notification);","handlingStrategy":"validation","validationCode":"// Track whether fit() was applied; never combine with RemoteViews loads\nboolean useFit = target instanceof ImageView;\nRequestCreator rc = picasso.load(url);\nif (useFit) rc.fit(); else rc.resize(size, size);\nrc.into(remoteViews, viewId, notifId, notification);","typeGuard":null,"tryCatchPattern":"Not useful: IllegalStateException here is deterministic API misuse; it should be prevented, not caught. Fix the builder chain.","preventionTips":["Encapsulate notification/widget image loads in one helper that never calls fit().","Reserve fit() for ImageView targets only.","Add a lint/Detekt-style grep for \".fit()\" near \"RemoteViews\"."],"tags":["android","picasso","remoteviews","notification","api-misuse"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}