didi/DoKit · error · IllegalStateException

Fit cannot be used with RemoteViews.

Error message

Fit cannot be used with RemoteViews.

What it means

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.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java:565

        picasso.enqueueAndSubmit(action);
    }

    /**
     * Asynchronously fulfills the request into the specified {@link RemoteViews} object with the
     * given {@code viewId}. This is used for loading bitmaps into a {@link Notification}.
     */
    public void into(RemoteViews remoteViews, int viewId, int notificationId,
                     Notification notification) {
        long started = System.nanoTime();

        if (remoteViews == null) {
            throw new IllegalArgumentException("RemoteViews must not be null.");
        }
        if (notification == null) {
            throw new IllegalArgumentException("Notification must not be null.");
        }
        if (deferred) {
            throw new IllegalStateException("Fit cannot be used with RemoteViews.");
        }
        if (placeholderDrawable != null || placeholderResId != 0 || errorDrawable != null) {
            throw new IllegalArgumentException(
                    "Cannot use placeholder or error drawables with remote views.");
        }

        Request request = createRequest(started);
        String key = createKey(request, new StringBuilder()); // Non-main thread needs own builder.

        RemoteViewsAction action =
                new NotificationAction(picasso, request, remoteViews, viewId, notificationId, notification,
                        memoryPolicy, networkPolicy, key, tag, errorResId);

        performRemoteViewInto(action);
    }

    /**
     * Asynchronously fulfills the request into the specified {@link RemoteViews} object with the

View on GitHub (pinned to 626827cddb)

Solutions

  1. Remove the .fit() call from the request builder used for the notification RemoteViews load.
  2. If a specific icon size is required, use .resize(w, h) or .resizeDimen(...) instead of fit(), since resize is compatible with RemoteViews.
  3. Keep two separate builder chains: one with fit() for ImageView targets, one without for RemoteViews/notification targets.

Example fix

// before
picasso.load(url).fit().into(remoteViews, R.id.icon, notifId, notification);

// after
picasso.load(url).resize(smallIconSize, smallIconSize).into(remoteViews, R.id.icon, notifId, notification);
Defensive patterns

Strategy: validation

Validate before calling

// Track whether fit() was applied; never combine with RemoteViews loads
boolean useFit = target instanceof ImageView;
RequestCreator rc = picasso.load(url);
if (useFit) rc.fit(); else rc.resize(size, size);
rc.into(remoteViews, viewId, notifId, notification);

Try / catch

Not useful: IllegalStateException here is deterministic API misuse; it should be prevented, not caught. Fix the builder chain.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/3125cc69114b9570. Report an issue: GitHub.