0

When I use HIChartView in a layout that is inflated using AsyncLayoutInflater and added to a FrameLayout Highcharts throws java.lang.IllegalStateException. However if I switch to traditional LayoutInflater no exception is thrown.

Exception:

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) 

The code I use for inflation and adding to parent:

new AsyncLayoutInflater(this).inflate(R.layout.bottom_sheet_contents, sheetLayout, (view, resid, parent) -> {
        parent.addView(view);
        detailsViewReady = true;
    });
Eray Ocak
  • 1
  • 1
  • `HIChartView` is apparently using `WebView` internally, and that never has worked with `AsyncLayoutInflater`, AFAIK. `WebView` must be instantiated on the main thread. If you have to use `HIChartView`, then you'll have to inflate it the old fashioned way. Otherwise, you might have to find a different library. – Mike M. Aug 07 '20 at 19:49
  • Oh I got it. Are there any ways to postpone the inflation inside onCreate you know. I don't want LayoutInflater to slow down activity creation. – Eray Ocak Aug 07 '20 at 19:53
  • Sure, you can postpone to whenever you like, but since `HIChartView` apparently must be instantiated on the main thread, it's gonna have to do its work there sooner or later. I mean, no matter when you finally do it, it'll take the same amount of time on the main thread, whether it's in `onCreate()` or not. You might want to do a little testing first to make sure that the inflation is causing enough of a delay to justify fiddling with your setup. – Mike M. Aug 07 '20 at 20:05

0 Answers0