Blankj/AndroidUtilCode · error · IllegalArgumentException
presenterClass is null!
Error message
presenterClass is null!
What it means
BaseView.getPresenter(Class) throws IllegalArgumentException when the requested presenter class argument is null. It is a contract check: a null class key cannot be looked up in the presenter map, so the call is rejected before any map access.
Source
Thrown at lib/base/src/main/java/com/blankj/base/mvp/BaseView.java:76
public <T extends Fragment> T getFragment() {
if (mFragment == null) {
return null;
}
//noinspection unchecked
return (T) mFragment;
}
public V addPresenter(BasePresenter<V> presenter) {
if (presenter == null) return (V) this;
mPresenterMap.put(presenter.getClass(), presenter);
//noinspection unchecked
presenter.bindView((V) this);
return (V) this;
}
public <P extends BasePresenter<V>> P getPresenter(Class<P> presenterClass) {
if (presenterClass == null) {
throw new IllegalArgumentException("presenterClass is null!");
}
BasePresenter<V> basePresenter = mPresenterMap.get(presenterClass);
if (basePresenter == null) {
throw new IllegalArgumentException("presenter of <" + presenterClass.getSimpleName() + "> is not added!");
}
//noinspection unchecked
return (P) basePresenter;
}
@CallSuper
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() {
Log.i(TAG, "destroy view: " + getClass().getSimpleName());
removeLifecycle(this);
for (BasePresenter<V> presenter : mPresenterMap.values()) {
if (presenter != null) {
presenter.onDestroy();
}View on GitHub (pinned to 7b4caf9e54)
Solutions
- Pass the concrete presenter class literal, e.g. getPresenter(LoginPresenter.class), never a possibly-null variable.
- Initialise any Class field you intend to pass before the getPresenter call, or assert it is non-null.
- If the presenter class is optional, branch on the field being null instead of calling getPresenter(null).
Example fix
// before Class<? extends BasePresenter<V>> cls = null; getPresenter(cls); // throws // after getPresenter(LoginPresenter.class);
Defensive patterns
Strategy: validation
Validate before calling
if (presenterClass != null) {
getPresenter(presenterClass);
} Type guard
private static boolean isPresenterClassKnown(Class<?> c) {
return c != null && BasePresenter.class.isAssignableFrom(c);
} Prevention
- Pass concrete class literals (XPresenter.class), never nullable variables.
- Initialise any Class field before using it as a getPresenter key.
- Branch on null instead of forwarding it to getPresenter.
When it happens
Trigger: Calling getPresenter(null), or getPresenter(someField) where someField is a Class reference that has not been initialised (still null), e.g. a presenter class loaded lazily or conditionally.
Common situations: A field holding the presenter Class is left null due to a missed initialisation; passing a Class obtained from a dynamic lookup that returned null; copy-paste leaving a placeholder null in a getPresenter call.
Related errors
- presenter of <{}> is not added!
- ContentView is null.
- context is not instance of Activity.
- onCreateViewHolder: get holder from view type failed.
- Invalid orientation. It should be either HORIZONTAL or VERTI
AI-assisted analysis of Blankj/AndroidUtilCode@7b4caf9e54 (2026-08-14).
Data as JSON: /api/errors/0df09ae2ee6266b5.
Report an issue: GitHub.