bumptech/glide · error · IllegalArgumentException
You cannot start a load on a null Context
Error message
You cannot start a load on a null Context
What it means
IllegalArgumentException thrown by RequestManagerRetriever.get(Context) when the supplied Context is null. Glide requires a non-null Context (Application, Activity, FragmentActivity, or ContextWrapper) to scope the RequestManager lifecycle.
Source
Thrown at library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java:90
// TODO(b/27524013): Factor out this Glide.get() call.
Glide glide = Glide.get(context.getApplicationContext());
applicationManager =
factory.build(
glide,
new ApplicationLifecycle(),
new EmptyRequestManagerTreeNode(),
context.getApplicationContext());
}
}
}
return applicationManager;
}
@NonNull
public RequestManager get(@NonNull Context context) {
if (context == null) {
throw new IllegalArgumentException("You cannot start a load on a null Context");
} else if (Util.isOnMainThread() && !(context instanceof Application)) {
if (context instanceof FragmentActivity) {
return get((FragmentActivity) context);
} else if (context instanceof ContextWrapper
// Only unwrap a ContextWrapper if the baseContext has a non-null application context.
// Context#createPackageContext may return a Context without an Application instance,
// in which case a ContextWrapper may be used to attach one.
&& ((ContextWrapper) context).getBaseContext().getApplicationContext() != null) {
return get(((ContextWrapper) context).getBaseContext());
}
}
return getApplicationManager(context);
}
@NonNull
public RequestManager get(@NonNull FragmentActivity activity) {
if (Util.isOnBackgroundThread()) {View on GitHub (pinned to eb14a895d8)
Solutions
- Use Glide.with(view) or Glide.with(applicationContext) where Context may be null.
- Null-check the Context before calling Glide.with().
- In fragments, prefer Glide.with(this) (the fragment) over Glide.with(getActivity()).
Example fix
// before
Glide.with(getActivity()).load(url).into(img); // getActivity() can be null
// after
Context ctx = getContext();
if (ctx != null) {
Glide.with(ctx).load(url).into(img);
} Defensive patterns
Strategy: type-guard
Validate before calling
// Null-check Context (or use View) before calling Glide.with().
Context ctx = getView() != null ? getView().getContext() : null;
if (ctx != null) {
Glide.with(ctx).load(url).into(img);
} Type guard
// Kotlin guard val ctx: Context? = view?.context if (ctx != null) Glide.with(ctx).load(url).into(img)
Prevention
- Prefer Glide.with(view) which tolerates detached views better than null Context.
- Null-check Context obtained from getActivity()/getContext() in callbacks.
- Avoid holding Activity references that may be nulled on destroy.
When it happens
Trigger: Calling Glide.with(null), or Glide.with((Context) someField) where the field is null (e.g. in a detached fragment whose getContext() is null).
Common situations: Calling Glide.with() from a constructor or field that has not been initialized. Using Glide.with(getActivity()) after the activity has been destroyed and field nulled. Passing a nullable Context from an interop layer without null-checking.
Related errors
- You cannot start a load for a destroyed activity
- Cannot register already registered manager
- Cannot unregister not yet registered manager
- BufferedInputStream is closed
- Stream is closed
AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14).
Data as JSON: /api/errors/08bfc57a7b269b0e.
Report an issue: GitHub.