didi/DoKit · error · IllegalArgumentException
Target must not be null.
Error message
Target must not be null.
What it means
Thrown by RequestCreator.into(Target) when the Target argument is null. A Target receives the loaded bitmap callbacks, so a null target has nothing to deliver to; Picasso validates on the main thread (checkMain runs first) and throws IllegalArgumentException.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java:518
* frame.setBackgroundResource(R.drawable.profile_error);
* }
*
* {@literal @}Override public void onPrepareLoad(Drawable placeHolderDrawable) {
* frame.setBackgroundDrawable(placeHolderDrawable);
* }
* }
* </pre></blockquote>
* <p>
* <em>Note:</em> This method keeps a weak reference to the {@link Target} instance and will be
* garbage collected if you do not keep a strong reference to it. To receive callbacks when an
* image is loaded use {@link #into(android.widget.ImageView, Callback)}.
*/
public void into(Target target) {
long started = System.nanoTime();
checkMain();
if (target == null) {
throw new IllegalArgumentException("Target must not be null.");
}
if (deferred) {
throw new IllegalStateException("Fit cannot be used with a Target.");
}
if (!data.hasImage()) {
picasso.cancelRequest(target);
target.onPrepareLoad(setPlaceholder ? getPlaceholderDrawable() : null);
return;
}
Request request = createRequest(started);
String requestKey = createKey(request);
if (shouldReadFromMemoryCache(memoryPolicy)) {
Bitmap bitmap = picasso.quickMemoryCacheCheck(requestKey);
if (bitmap != null) {
picasso.cancelRequest(target);View on GitHub (pinned to 626827cddb)
Solutions
- Pass a non-null Target implementation and keep a strong reference to it (into(Target) holds only a weak reference)
- If the target is optional by the time the call runs, guard: if (target != null) rc.into(target); else rc.fetch(null);
- Initialize the Target field before building the request chain
Example fix
// before
private Target target; // not yet assigned
picasso.load(url).into(target); // throws "Target must not be null."
// after
target = new Target() { /* onBitmapLoaded/onBitmapFailed */ };
picasso.load(url).into(target); Defensive patterns
Strategy: validation
Validate before calling
if (target != null) {
picasso.load(url).into(target);
} else {
picasso.load(url).fetch(null); // warm cache instead
} Type guard
static boolean isUsableTarget(Target t) {
return t != null;
} Prevention
- Initialize Target fields before any load call
- Keep a strong reference to the Target for as long as you need callbacks — into(Target) holds only a weak one
- Prefer into(imageView, callback) when the destination is really an ImageView
When it happens
Trigger: Calling .into((Target) null), or passing a Target field that was not yet initialized / was nulled after a lifecycle event.
Common situations: Fields like custom Target instances referenced before initialization in onCreate; passing a weakly-held Target that was garbage-collected and left null; Kotlin nullable Target passed without !!-style checks.
Related errors
- Error image may not be null.
- Tag invalid.
- Memory policy cannot be null.
- Network policy cannot be null.
- Fit cannot be used with a Target.
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/b96858042b9a3249.
Report an issue: GitHub.