{"record":{"id":"c342c10f83f01ee9","repo":"alibaba/ARouter","slug":"aroutercore-init-invoke-init-context-first","errorCode":null,"errorMessage":"ARouterCore::Init::Invoke init(context) first!","messagePattern":"ARouterCore::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":88,"sourceCode":"        return true;\n    }\n\n    /**\n     * Destroy arouter, it can be used only in debug mode.\n     */\n    static synchronized void destroy() {\n        if (debuggable()) {\n            hasInit = false;\n            LogisticsCenter.suspend();\n            logger.info(Consts.TAG, \"ARouter destroy success!\");\n        } else {\n            logger.error(Consts.TAG, \"Destroy can be used in debug mode only!\");\n        }\n    }\n\n    protected static _ARouter getInstance() {\n        if (!hasInit) {\n            throw new InitException(\"ARouterCore::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    static synchronized void openDebug() {\n        debuggable = true;\n        logger.info(Consts.TAG, \"ARouter openDebug\");\n    }\n\n    static synchronized void openLog() {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/alibaba/ARouter/blob/84f451d244e3fb1d0e37801de1b9ee2af2f81d68/arouter-api/src/main/java/com/alibaba/android/arouter/launcher/_ARouter.java#L70-L106","documentation":"_ARouter.getInstance() is the internal core accessor and throws InitException when hasInit is false. The core is only usable after ARouter.init(context) populated the generated route metadata; failing fast prevents navigation against an empty route map.","triggerScenarios":"Any API that internally reaches _ARouter.getInstance() (build, navigation, inject, hasRoute) executed before ARouter.init(context) finished, or after init failed.","commonSituations":"Same root cause as the public ARouter init error: missing init in Application, init failure due to missing ARouter$$Root/ARouter$$Providers generated classes, or unit tests invoking routing APIs without a fake init.","solutions":["Initialize ARouter in Application.onCreate() before anything else uses routing","If init fails, verify annotation processors (arouter-compiler) ran and the module's generated classes are packaged (clean build)","For instrumented/unit tests, initialize with the test Application context before calling routing APIs"],"exampleFix":"// before\nprotected void onCreate(Bundle b) {\n    ARouter.getInstance().build(\"/user/login\").navigation(); // reaches _ARouter, throws\n// after\n@Override protected void onCreate(Bundle b) {\n    if (!ARouter.debuggable()) { /* init already done in Application */ }\n    ARouter.getInstance().build(\"/user/login\").navigation();","handlingStrategy":"validation","validationCode":"if (application == null || !isMainProcessReady()) {\n    return; // skip routing until init completed\n}","typeGuard":null,"tryCatchPattern":"try {\n    ARouter.getInstance().inject(this);\n} catch (InitException e) {\n    Log.e(TAG, \"Router core not initialized\", e);\n}","preventionTips":["Single init point in Application.onCreate","Avoid routing calls in tests without an initialized Application","Keep arouter-api and compiler plugin versions in sync so init succeeds"],"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-14T05:17:10.506Z"}