{"record":{"id":"b592d0b5a2c7819c","repo":"Justson/AgentWeb","slug":"please-check-webcreator-s-create-method-was-be-cal","errorCode":null,"errorMessage":"please check webcreator's create method was be called ?","messagePattern":"please check webcreator's create method was be called \\?","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java","lineNumber":830,"sourceCode":"\t//获取应用的名称\n\tpublic static String getApplicationName(Context context) {\n\t\tPackageManager packageManager = null;\n\t\tApplicationInfo applicationInfo = null;\n\t\ttry {\n\t\t\tpackageManager = context.getApplicationContext().getPackageManager();\n\t\t\tapplicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);\n\t\t} catch (PackageManager.NameNotFoundException e) {\n\t\t\tapplicationInfo = null;\n\t\t}\n\t\tString applicationName =\n\t\t\t\t(String) packageManager.getApplicationLabel(applicationInfo);\n\t\treturn applicationName;\n\t}\n\n\tstatic WebParentLayout getWebParentLayoutByWebView(WebView webView) {\n\t\tViewGroup mViewGroup = null;\n\t\tif (!(webView.getParent() instanceof ViewGroup)) {\n\t\t\tthrow new IllegalStateException(\"please check webcreator's create method was be called ?\");\n\t\t}\n\t\tmViewGroup = (ViewGroup) webView.getParent();\n\t\tAbsAgentWebUIController mAgentWebUIController;\n\t\twhile (mViewGroup != null) {\n\n\t\t\tLogUtils.i(TAG, \"ViewGroup:\" + mViewGroup);\n\t\t\tif (mViewGroup.getId() == R.id.web_parent_layout_id) {\n\t\t\t\tWebParentLayout mWebParentLayout = (WebParentLayout) mViewGroup;\n\t\t\t\tLogUtils.i(TAG, \"found WebParentLayout\");\n\t\t\t\treturn mWebParentLayout;\n\t\t\t} else {\n\t\t\t\tViewParent mViewParent = mViewGroup.getParent();\n\t\t\t\tif (mViewParent instanceof ViewGroup) {\n\t\t\t\t\tmViewGroup = (ViewGroup) mViewParent;\n\t\t\t\t} else {\n\t\t\t\t\tmViewGroup = null;\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":812,"sourceCodeEnd":848,"githubUrl":"https://github.com/Justson/AgentWeb/blob/8f7f6adbf01010e9b2b44638f31edf10e1ba53f7/agentweb-core/src/main/java/com/just/agentweb/AgentWebUtils.java#L812-L848","documentation":"AgentWebUtils.getWebParentLayoutByWebView throws IllegalStateException when the given WebView has no parent ViewGroup, meaning it was never attached through AgentWeb's create() flow. The method walks up the view hierarchy to find the WebParentLayout; without a parent it cannot locate AgentWeb's internal UI controller. The message points to the create method because AgentWeb's create() is what attaches the WebView.","triggerScenarios":"Calling AgentWebUtils APIs that take a WebView (e.g. permission/UI-controller helpers) with a WebView created outside AgentWeb, or before createAgentWeb().go()/create() attached it, or after it was removed from its parent.","commonSituations":"Using AgentWebUtils with a plain manually-instantiated WebView, calling utility methods in a Fragment's onDestroy after the view tree was torn down, or invoking before AgentWeb's ready()/go() completes.","solutions":["Only call this utility with a WebView produced and attached by AgentWeb (after createAgentWeb().go())","Verify webView.getParent() != null before calling","If you must use a custom WebView, integrate it via AgentWeb's builder (setWebView) rather than standalone","Move utility calls out of teardown phases (onDestroyView/onDetach) where the view is already unparented"],"exampleFix":"// before\nAgentWebUtils.getWebParentLayoutByWebView(myStandaloneWebView); // parent is null\n// after\nif (myStandaloneWebView.getParent() instanceof ViewGroup) {\n    AgentWebUtils.getWebParentLayoutByWebView(myStandaloneWebView);\n}","handlingStrategy":"type-guard","validationCode":"if (!(webView.getParent() instanceof ViewGroup)) { return; }","typeGuard":"boolean webviewAttachedByAgentWeb(WebView w) { return w != null && w.getParent() instanceof ViewGroup; }","tryCatchPattern":"try { WebParentLayout l = AgentWebUtils.getWebParentLayoutByWebView(wv); } catch (IllegalStateException e) { Log.w(TAG, \"webview not attached via AgentWeb\", e); }","preventionTips":["Only pass AgentWeb-managed WebViews to AgentWebUtils","Call after createAgentWeb().go() completes","Don't call during/after onDestroy teardown","Avoid removing the WebView from its parent"],"tags":["android","illegal-state","webview","agentweb-utils"],"backgroundTag":"invalid-state-transition","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"}