当我在使用 AsyncLayoutInflater 膨胀并添加到 FrameLayout Highcharts 的布局中使用 HIChartView 时,会抛出 java.lang.IllegalStateException。但是,如果我切换到传统的 LayoutInflater,则不会引发异常。
例外:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test, PID: 30996
android.view.InflateException: Binary XML file line #201 in com.test:layout/bottom_sheet_contents: Binary XML file line #201 in com.test:layout/bottom_sheet_contents: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #201 in com.test:layout/bottom_sheet_contents: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:858)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at androidx.asynclayoutinflater.view.AsyncLayoutInflater$1.handleMessage(AsyncLayoutInflater.java:100)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.IllegalStateException: AwContents must be created if we are not posting!
at Db.c(chromium-TrichromeWebViewGoogle.aab-stable-1:5)
at com.android.webview.chromium.WebViewChromium.a(chromium-TrichromeWebViewGoogle.aab-stable-1:1)
at com.android.webview.chromium.WebViewChromium.addJavascriptInterface(chromium-TrichromeWebViewGoogle.aab-stable-1:1)
at cd.run(chromium-TrichromeWebViewGoogle.aab-stable-1:1)
at lx.b(chromium-TrichromeWebViewGoogle.aab-stable-1:3)
at de.i(chromium-TrichromeWebViewGoogle.aab-stable-1:78)
at de.b(chromium-TrichromeWebViewGoogle.aab-stable-1:15)
at de.k(chromium-TrichromeWebViewGoogle.aab-stable-1:2)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.g(chromium-TrichromeWebViewGoogle.aab-stable-1:2)
at com.android.webview.chromium.WebViewChromium.init(chromium-TrichromeWebViewGoogle.aab-stable-1:14)
at android.webkit.WebView.<init>(WebView.java:429)
at android.webkit.WebView.<init>(WebView.java:353)
at android.webkit.WebView.<init>(WebView.java:336)
at android.webkit.WebView.<init>(WebView.java:323)
at android.webkit.WebView.<init>(WebView.java:313)
at com.highsoft.highcharts.core.HIChartView.a(SourceFile:4)
at com.highsoft.highcharts.core.HIChartView.<init>(SourceFile:563)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:858)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at androidx.asynclayoutinflater.view.AsyncLayoutInflater$1.handleMessage(AsyncLayoutInflater.java:100)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
我用于通货膨胀并添加到父级的代码:
new AsyncLayoutInflater(this).inflate(R.layout.bottom_sheet_contents, sheetLayout, (view, resid, parent) -> {
parent.addView(view);
detailsViewReady = true;
});