didi/DoKit · error · IllegalStateException
Fit cannot be used with fetch.
Error message
Fit cannot be used with fetch.
What it means
Thrown by RequestCreator.fetch(Callback) when the chain called fit(). fit() defers the request until a target ImageView is laid out and measured; fetch() has no view target at all (it warms the cache), so the combination is rejected with IllegalStateException.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java:441
*/
public void fetch() {
fetch(null);
}
/**
* Asynchronously fulfills the request without a {@link ImageView} or {@link Target},
* and invokes the target {@link Callback} with the result. This is useful when you want to warm
* up the cache with an image.
* <p>
* <em>Note:</em> The {@link Callback} param is a strong reference and will prevent your
* {@link android.app.Activity} or {@link android.app.Fragment} from being garbage collected
* until the request is completed.
*/
public void fetch(Callback callback) {
long started = System.nanoTime();
if (deferred) {
throw new IllegalStateException("Fit cannot be used with fetch.");
}
if (data.hasImage()) {
// Fetch requests have lower priority by default.
if (!data.hasPriority()) {
data.priority(Priority.LOW);
}
Request request = createRequest(started);
String key = createKey(request, new StringBuilder());
Bitmap bitmap = picasso.quickMemoryCacheCheck(key);
if (bitmap != null) {
if (picasso.loggingEnabled) {
log(OWNER_MAIN, VERB_COMPLETED, request.plainId(), "from " + MEMORY);
}
if (callback != null) {
callback.onSuccess();
}View on GitHub (pinned to 626827cddb)
Solutions
- Remove fit() from the fetch() chain and size explicitly: .resize(w, h).fetch(null)
- Duplicate the chain: keep fit()+into(imageView) for display and a separate resize()+fetch() for prefetch
- Pass null as the callback if you only want cache warming, and drop fit()
Example fix
// before picasso.load(url).fit().fetch(null); // throws "Fit cannot be used with fetch." // after picasso.load(url).resize(targetWidth, targetHeight).centerInside().fetch(null);
Defensive patterns
Strategy: validation
Validate before calling
// Prefetch path: explicit size, no fit picasso.load(url).resize(targetW, targetH).centerInside().fetch(null); // Display path: fit is fine picasso.load(url).fit().into(imageView);
Prevention
- Keep separate chain builders for display (fit allowed) and cache warm-up (no fit)
- Pass null callback to fetch() when callbacks are not needed
- Mirror the target view's dimensions with resize() so prefetched entries actually hit the cache key used later
When it happens
Trigger: Calling picasso.load(url).fit().fetch(...), typically while refactoring an into(imageView) chain into a cache-warming prefetch.
Common situations: Preloading the next screen's images by copy-pasting the render chain (with fit()) and swapping into() for fetch(); RecyclerView prefetch helpers reusing the same builder configuration for both display and warm-up.
Related errors
- Fit cannot be used with get.
- Fit cannot be used with a Target.
- Error image resource invalid.
- Error image already set.
- Error image may not be null.
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/a020117606f0a7af.
Report an issue: GitHub.