{"record":{"id":"f3d1e61d17c1c8d6","repo":"Blankj/AndroidUtilCode","slug":"presenter-of-is-not-added","errorCode":null,"errorMessage":"presenter of <{}> is not added!","messagePattern":"presenter of <(.+?)> is not added!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/base/src/main/java/com/blankj/base/mvp/BaseView.java","lineNumber":80,"sourceCode":"        //noinspection unchecked\n        return (T) mFragment;\n    }\n\n    public V addPresenter(BasePresenter<V> presenter) {\n        if (presenter == null) return (V) this;\n        mPresenterMap.put(presenter.getClass(), presenter);\n        //noinspection unchecked\n        presenter.bindView((V) this);\n        return (V) this;\n    }\n\n    public <P extends BasePresenter<V>> P getPresenter(Class<P> presenterClass) {\n        if (presenterClass == null) {\n            throw new IllegalArgumentException(\"presenterClass is null!\");\n        }\n        BasePresenter<V> basePresenter = mPresenterMap.get(presenterClass);\n        if (basePresenter == null) {\n            throw new IllegalArgumentException(\"presenter of <\" + presenterClass.getSimpleName() + \"> is not added!\");\n        }\n        //noinspection unchecked\n        return (P) basePresenter;\n    }\n\n    @CallSuper\n    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)\n    public void onDestroy() {\n        Log.i(TAG, \"destroy view: \" + getClass().getSimpleName());\n        removeLifecycle(this);\n        for (BasePresenter<V> presenter : mPresenterMap.values()) {\n            if (presenter != null) {\n                presenter.onDestroy();\n            }\n        }\n        mPresenterMap.clear();\n    }\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/base/src/main/java/com/blankj/base/mvp/BaseView.java#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\ngetPresenter(LoginPresenter.class); // throws: never added\n\n// after\naddPresenter(new LoginPresenter());\ngetPresenter(LoginPresenter.class);","handlingStrategy":"validation","validationCode":"// Register the presenter in the view constructor, then query by the same class.\naddPresenter(new LoginPresenter());\n// ...\nLoginPresenter p = getPresenter(LoginPresenter.class);","typeGuard":null,"tryCatchPattern":"try {\n    P p = getPresenter(SomePresenter.class);\n} catch (IllegalArgumentException e) {\n    // presenter not registered; register it or degrade\n}","preventionTips":["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."],"tags":["android","mvp","registration","contract"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}