Justson/AgentWeb · error · NullPointerException
ViewGroup is null,Please check your parameters .
Error message
ViewGroup is null,Please check your parameters .
What it means
AgentWeb.Builder.build() throws NullPointerException when the target ViewGroup is null for a Fragment-based AgentWeb (mTag == AgentWeb.FRAGMENT_TAG). AgentWeb must know which parent container to attach the WebView to; without it, layout inflation cannot proceed. The check is skipped for the Activity tag where a default parent is derived differently.
Solutions
- Call .setWebViewParent(container, index) on the Builder before build()
- Verify the container variable is non-null at build time (e.g. a layout view inflated in onViewCreated)
- Ensure you are not building in a lifecycle stage before the container view exists
- If using the Activity variant, confirm AgentWeb.with(activity) was used so the FRAGMENT_TAG path is not taken
Example fix
// before
AgentWeb.with(this).createAgentWeb().ready(); // never set parent
// after
AgentWeb.with(this)
.setWebViewParent((ViewGroup) view.findViewById(R.id.web_container), -1)
.createAgentWeb().ready(); Defensive patterns
Strategy: validation
Validate before calling
if (container == null) { throw new IllegalStateException("setWebViewParent required before build()"); } Type guard
boolean builderReady(AgentWeb.AgentBuilder b, ViewGroup p) { return p != null && p.getChildCount() >= 0; } Try / catch
try { pre = builder.buildAgentWeb(); } catch (NullPointerException e) { Log.e(TAG, "missing ViewGroup parent", e); } Prevention
- Always chain setWebViewParent before build() in Fragment mode
- Inflate the container before AgentWeb setup
- Keep container lookup and build in the same method
- Assert container != null in code review for Fragment usage
When it happens
Trigger: Calling build() after AgentWeb.with(fragment) without ever invoking .setWebViewParent(viewGroup, index) (or the equivalent setter) on the Builder.
Common situations: Forgetting the setWebViewParent call when copying sample code that used the Activity variant, conditionally setting the parent and the condition failing, or refactoring so the ViewGroup field is assigned after build() is called.
Related errors
- activity can not be null .
- please check webcreator's create method was be called ?
- injected name can not be null
- the WebView related to the JsCallback has been recycled
- the JsCallback isn't permanent,cannot be called more than…
AI-assisted analysis of Justson/AgentWeb@8f7f6adbf0 (2026-09-11).
Data as JSON: /api/errors/4959c4b30ff8980c.
Report an issue: GitHub.
Appendix: source
Thrown at agentweb-core/src/main/java/com/just/agentweb/AgentWeb.java:549
}
public IndicatorBuilder setAgentWebParent(@NonNull ViewGroup v, @NonNull ViewGroup.LayoutParams lp) {
this.mViewGroup = v;
this.mLayoutParams = lp;
return new IndicatorBuilder(this);
}
public IndicatorBuilder setAgentWebParent(@NonNull ViewGroup v, int index, @NonNull ViewGroup.LayoutParams lp) {
this.mViewGroup = v;
this.mLayoutParams = lp;
this.mIndex = index;
return new IndicatorBuilder(this);
}
private PreAgentWeb buildAgentWeb() {
if (mTag == AgentWeb.FRAGMENT_TAG && this.mViewGroup == null) {
throw new NullPointerException("ViewGroup is null,Please check your parameters .");
}
return new PreAgentWeb(HookManager.hookAgentWeb(new AgentWeb(this), this));
}
private void addJavaObject(String key, Object o) {
if (mJavaObject == null) {
mJavaObject = new ArrayMap<>();
}
mJavaObject.put(key, o);
}
private void addHeader(String baseUrl, String k, String v) {
if (mHttpHeaders == null) {
mHttpHeaders = HttpHeaders.create();
}
mHttpHeaders.additionalHttpHeader(baseUrl, k, v);
}
View on GitHub (pinned to 8f7f6adbf0)