Blankj/AndroidUtilCode · error · IllegalArgumentException
presenter of <{}> is not added!
Error message
presenter of <{}> is not added! What it means
BaseView.getPresenter throws IllegalArgumentException when the requested presenter class is not null but was never registered via addPresenter. The presenter map only contains classes passed to addPresenter(presenter), so any unregistered class key yields this error.
Source
Thrown at lib/base/src/main/java/com/blankj/base/mvp/BaseView.java:80
//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();
}
}
mPresenterMap.clear();
}
View on GitHub (pinned to 7b4caf9e54)
Solutions
- Register the presenter first: addPresenter(new LoginPresenter()) (chained in the view constructor), then call getPresenter(LoginPresenter.class).
- Query with the exact same Class you registered — HashMap.get uses Class.equals/hashCode, so a superclass key will not match a subclass-registered presenter.
- Do not call getPresenter after the view's ON_DESTROY has run (onDestroy clears mPresenterMap).
Example fix
// before getPresenter(LoginPresenter.class); // throws: never added // after addPresenter(new LoginPresenter()); getPresenter(LoginPresenter.class);
Defensive patterns
Strategy: validation
Validate before calling
// Register the presenter in the view constructor, then query by the same class. addPresenter(new LoginPresenter()); // ... LoginPresenter p = getPresenter(LoginPresenter.class);
Try / catch
try {
P p = getPresenter(SomePresenter.class);
} catch (IllegalArgumentException e) {
// presenter not registered; register it or degrade
} Prevention
- Register every presenter via addPresenter in the view setup before querying.
- Query with the exact Class you registered (HashMap uses precise Class keys).
- Do not call getPresenter after ON_DESTROY cleared the map.
When it happens
Trigger: Calling getPresenter(XPresenter.class) without a prior addPresenter(new XPresenter()) on the same BaseView; requesting a presenter before the view's construction adds it; using a different class instance (subclass vs. registered class) as the key.
Common situations: Forgetting to register the presenter in the view constructor/setup; registering a concrete presenter then querying by its abstract superclass (HashMap uses exact Class key); calling getPresenter after onDestroy cleared the map.
Related errors
- presenterClass is null!
- 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/f3d1e61d17c1c8d6.
Report an issue: GitHub.