alibaba/ARouter · critical · InitException
ARouter::Init::Invoke init(context) first!
Error message
ARouter::Init::Invoke init(context) first!
What it means
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.
Source
Thrown at arouter-api/src/main/java/com/alibaba/android/arouter/launcher/ARouter.java:60
logger = _ARouter.logger;
_ARouter.logger.info(Consts.TAG, "ARouter init start.");
hasInit = _ARouter.init(application);
if (hasInit) {
_ARouter.afterInit();
}
_ARouter.logger.info(Consts.TAG, "ARouter init over.");
}
}
/**
* Get instance of router. A
* All feature U use, will be starts here.
*/
public static ARouter getInstance() {
if (!hasInit) {
throw new InitException("ARouter::Init::Invoke init(context) first!");
} else {
if (instance == null) {
synchronized (ARouter.class) {
if (instance == null) {
instance = new ARouter();
}
}
}
return instance;
}
}
public static synchronized void openDebug() {
_ARouter.openDebug();
}
public static boolean debuggable() {
return _ARouter.debuggable();View on GitHub (pinned to 84f451d244)
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)
Example fix
// before
ARouter.getInstance().build("/main/activity").navigation(); // InitException
// after
public class App extends Application {
@Override public void onCreate() {
super.onCreate();
ARouter.init(this); // must run before any getInstance()/build()
}
} Defensive patterns
Strategy: validation
Validate before calling
// guard before any ARouter API
public static ARouter routerOrNull() {
try { return ARouter.getInstance(); } catch (Throwable t) { return null; }
} Type guard
public static boolean isArouterReady() {
try { return ARouter.getInstance() != null; } catch (Throwable t) { return false; }
} Try / catch
try {
ARouter.getInstance().build(path).navigation();
} catch (InitException e) {
Log.e(TAG, "ARouter not initialized", e);
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- ARouterCore::Init::Invoke init(context) first!
- The field '<fieldName>' is null, in class '<className>!
- Parameter is invalid!
- Parameter invalid!
- Extract the default group failed, the path must be start wit
AI-assisted analysis of alibaba/ARouter@84f451d244 (2026-09-06).
Data as JSON: /api/errors/953b369c6ca60dd3.
Report an issue: GitHub.