{"record":{"id":"4959c4b30ff8980c","repo":"Justson/AgentWeb","slug":"viewgroup-is-null-please-check-your-parameters","errorCode":null,"errorMessage":"ViewGroup is null,Please check your parameters .","messagePattern":"ViewGroup is null,Please check your parameters \\.","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"agentweb-core/src/main/java/com/just/agentweb/AgentWeb.java","lineNumber":549,"sourceCode":"        }\r\n\r\n\r\n        public IndicatorBuilder setAgentWebParent(@NonNull ViewGroup v, @NonNull ViewGroup.LayoutParams lp) {\r\n            this.mViewGroup = v;\r\n            this.mLayoutParams = lp;\r\n            return new IndicatorBuilder(this);\r\n        }\r\n\r\n        public IndicatorBuilder setAgentWebParent(@NonNull ViewGroup v, int index, @NonNull ViewGroup.LayoutParams lp) {\r\n            this.mViewGroup = v;\r\n            this.mLayoutParams = lp;\r\n            this.mIndex = index;\r\n            return new IndicatorBuilder(this);\r\n        }\r\n\r\n        private PreAgentWeb buildAgentWeb() {\r\n            if (mTag == AgentWeb.FRAGMENT_TAG && this.mViewGroup == null) {\r\n                throw new NullPointerException(\"ViewGroup is null,Please check your parameters .\");\r\n            }\r\n            return new PreAgentWeb(HookManager.hookAgentWeb(new AgentWeb(this), this));\r\n        }\r\n\r\n        private void addJavaObject(String key, Object o) {\r\n            if (mJavaObject == null) {\r\n                mJavaObject = new ArrayMap<>();\r\n            }\r\n            mJavaObject.put(key, o);\r\n        }\r\n\r\n        private void addHeader(String baseUrl, String k, String v) {\r\n            if (mHttpHeaders == null) {\r\n                mHttpHeaders = HttpHeaders.create();\r\n            }\r\n            mHttpHeaders.additionalHttpHeader(baseUrl, k, v);\r\n        }\r\n\r","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/Justson/AgentWeb/blob/8f7f6adbf01010e9b2b44638f31edf10e1ba53f7/agentweb-core/src/main/java/com/just/agentweb/AgentWeb.java#L531-L567","documentation":"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.","triggerScenarios":"Calling build() after AgentWeb.with(fragment) without ever invoking .setWebViewParent(viewGroup, index) (or the equivalent setter) on the Builder.","commonSituations":"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.","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"],"exampleFix":"// before\nAgentWeb.with(this).createAgentWeb().ready(); // never set parent\n// after\nAgentWeb.with(this)\n    .setWebViewParent((ViewGroup) view.findViewById(R.id.web_container), -1)\n    .createAgentWeb().ready();","handlingStrategy":"validation","validationCode":"if (container == null) { throw new IllegalStateException(\"setWebViewParent required before build()\"); }","typeGuard":"boolean builderReady(AgentWeb.AgentBuilder b, ViewGroup p) { return p != null && p.getChildCount() >= 0; }","tryCatchPattern":"try { pre = builder.buildAgentWeb(); } catch (NullPointerException e) { Log.e(TAG, \"missing ViewGroup parent\", e); }","preventionTips":["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"],"tags":["android","null-pointer","viewgroup","agentweb-builder"],"backgroundTag":"null-argument","analyzedSha":"8f7f6adbf01010e9b2b44638f31edf10e1ba53f7","analyzedAt":"2026-09-11T10:05:24.337Z","contentChangedAt":"2026-09-11T10:05:24.337Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}