{"record":{"id":"953b369c6ca60dd3","repo":"alibaba/ARouter","slug":"arouter-init-invoke-init-context-first","errorCode":null,"errorMessage":"ARouter::Init::Invoke init(context) first!","messagePattern":"ARouter::Init::Invoke init\\(context\\) first!","errorType":"exception","errorClass":"InitException","httpStatus":null,"severity":"critical","filePath":"arouter-api/src/main/java/com/alibaba/android/arouter/launcher/ARouter.java","lineNumber":60,"sourceCode":"            logger = _ARouter.logger;\n            _ARouter.logger.info(Consts.TAG, \"ARouter init start.\");\n            hasInit = _ARouter.init(application);\n\n            if (hasInit) {\n                _ARouter.afterInit();\n            }\n\n            _ARouter.logger.info(Consts.TAG, \"ARouter init over.\");\n        }\n    }\n\n    /**\n     * Get instance of router. A\n     * All feature U use, will be starts here.\n     */\n    public static ARouter getInstance() {\n        if (!hasInit) {\n            throw new InitException(\"ARouter::Init::Invoke init(context) first!\");\n        } else {\n            if (instance == null) {\n                synchronized (ARouter.class) {\n                    if (instance == null) {\n                        instance = new ARouter();\n                    }\n                }\n            }\n            return instance;\n        }\n    }\n\n    public static synchronized void openDebug() {\n        _ARouter.openDebug();\n    }\n\n    public static boolean debuggable() {\n        return _ARouter.debuggable();","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/alibaba/ARouter/blob/84f451d244e3fb1d0e37801de1b9ee2af2f81d68/arouter-api/src/main/java/com/alibaba/android/arouter/launcher/ARouter.java#L42-L78","documentation":"ARouter.getInstance() throws InitException when the router has not been initialized yet. ARouter requires an explicit init call (ARouter.init(Application)) before any routing API can be used; the facade class checks the hasInit flag and fails fast instead of returning a broken instance.","triggerScenarios":"Calling any ARouter static API (getInstance, build, navigation, inject) before ARouter.init(application) has completed, or after init failed (hasInit stays false because init logs the error internally and returns).","commonSituations":"Forgetting to call ARouter.init in a custom Application class or Application's onCreate not running (e.g. process started via a ContentProvider/test), init called on a background thread after a navigation attempt, or init failing silently because no generated ARouter$$Root module classes are on the classpath.","solutions":["Call ARouter.init(application) in your Application.onCreate() before any navigation","Check the logcat 'ARouter::' warning during init — if init failed, fix the missing generated router classes (run annotation processing, clean/rebuild)","Ensure the code calling getInstance runs after Application.onCreate (e.g. not in a static initializer)","In multi-process apps, call init for each process that routes (ARouter.init supports a delegate per process)"],"exampleFix":"// before\nARouter.getInstance().build(\"/main/activity\").navigation(); // InitException\n// after\npublic class App extends Application {\n    @Override public void onCreate() {\n        super.onCreate();\n        ARouter.init(this); // must run before any getInstance()/build()\n    }\n}","handlingStrategy":"validation","validationCode":"// guard before any ARouter API\npublic static ARouter routerOrNull() {\n    try { return ARouter.getInstance(); } catch (Throwable t) { return null; }\n}","typeGuard":"public static boolean isArouterReady() {\n    try { return ARouter.getInstance() != null; } catch (Throwable t) { return false; }\n}","tryCatchPattern":"try {\n    ARouter.getInstance().build(path).navigation();\n} catch (InitException e) {\n    Log.e(TAG, \"ARouter not initialized\", e);\n}","preventionTips":["Always call ARouter.init(application) first in Application.onCreate","Never call routing APIs in static initializers or constructors","Watch init logs for 'ARouter initialize success' in debug builds","Initialize in every process that uses routing"],"tags":["android","arouter","initialization-order","runtime"],"backgroundTag":"module-init-failed","analyzedSha":"84f451d244e3fb1d0e37801de1b9ee2af2f81d68","analyzedAt":"2026-09-06T13:30:41.084Z","contentChangedAt":"2026-09-06T13:30:41.084Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}