didi/DoKit · error · IllegalStateException
Fit cannot be used with get.
Error message
Fit cannot be used with get.
What it means
Thrown by RequestCreator.get() when the chain called fit(). fit() marks the request as deferred so it can wait for the target ImageView to be measured at layout time; get() is a synchronous, target-less API, so the two are fundamentally incompatible and Picasso throws IllegalStateException.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java:405
* Disable brief fade in of images loaded from the disk cache or network.
*/
public RequestCreator noFade() {
noFade = true;
return this;
}
/**
* Synchronously fulfill this request. Must not be called from the main thread.
* <p>
* <em>Note</em>: The result of this operation is not cached in memory because the underlying
* {@link Cache} implementation is not guaranteed to be thread-safe.
*/
public Bitmap get() throws IOException {
long started = System.nanoTime();
checkNotMain();
if (deferred) {
throw new IllegalStateException("Fit cannot be used with get.");
}
if (!data.hasImage()) {
return null;
}
Request finalData = createRequest(started);
String key = createKey(finalData, new StringBuilder());
Action action = new GetAction(picasso, finalData, memoryPolicy, networkPolicy, tag, key);
return forRequest(picasso, picasso.dispatcher, picasso.cache, picasso.stats, action).hunt();
}
/**
* Asynchronously fulfills the request without a {@link ImageView} or {@link Target}. This is
* useful when you want to warm up the cache with an image.
* <p>
* <em>Note:</em> It is safe to invoke this method from any thread.
*/View on GitHub (pinned to 626827cddb)
Solutions
- Remove fit() before get(), and specify explicit sizing instead: .resize(w, h).centerInside().get()
- If the image is destined for an ImageView, use into(imageView) and keep fit()
- For prefetching, drop fit() and use fetch(), or get() with resize() matching the view size
Example fix
// before Bitmap bmp = picasso.load(url).fit().get(); // throws "Fit cannot be used with get." // after Bitmap bmp = picasso.load(url).resize(1080, 1920).centerInside().get();
Defensive patterns
Strategy: validation
Validate before calling
RequestCreator rc = picasso.load(url);
if (needSync) {
Bitmap bmp = rc.resize(width, height).centerInside().get(); // no fit()
} else {
rc.fit().into(imageView);
} Prevention
- Remember fit() is only legal with into(ImageView); get(), fetch(), and into(Target) all reject it
- For synchronous loads, always supply explicit dimensions via resize()
- Do not copy display chains into prefetch/sync helpers without removing fit()
When it happens
Trigger: Calling picasso.load(url).fit().get(), e.g. to prefetch/measure the bitmap synchronously on a background thread while reusing fit() from an into() chain.
Common situations: Copying an into(imageView) chain (which used fit()) into a background preheat method that calls get(); adapting widget/AppWidget code that needs the Bitmap directly; unit-test helpers that synchronously load via get().
Related errors
- Fit cannot be used with fetch.
- 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/263bbaf0589a38ae.
Report an issue: GitHub.