Android Question Object should first be initialized (WebView). Did you forget to call Activity.LoadLayout?

D

Deleted member 103

Guest
Hi,
i have this firebase error.
Where could my fault be, if there is any fault at all?

Device: HUAWEI P20 lite
Marke: Android
Modell: S10+
Ausrichtung: Hochformat
Freier RAM: 262.3 MB
Freier Festplattenspeicher: 10.99 GB

Betriebssystem
Version: 9.1
Ausrichtung: Hochformat
Rooting durchgeführt: Nein

Absturz
Datum: 06.02.2020, 19:44:58
App-Version: 4.26.1 (62)

Fatal Exception: java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (WebView).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at fg.speedpilot_lite.main$ResumableSub_ShowPrivacyPolicy.resume(main.java:3654)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:190)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.agraham.dialogs.InputDialog$ExtendedBALayout$1.run(InputDialog.java:2467)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

Here is my B4a code:
B4X:
Sub Activity_Resume
...
    If Not(Starter.manager.getBoolean("IsPrivacyPolicyAllowed")) Then
        CallSubDelayed(Me, "ShowPrivacyPolicy")
    End If
...
End Sub

Private Sub ShowPrivacyPolicy
    Dim dialog As CustomLayoutDialog

    Dim sf As Object = dialog.ShowAsync("", "OK", "", "",Null, False)
    Wait For (sf) Dialog_Ready (DialogPanel As Panel)
    DialogPanel.LoadLayout("frmprivacypolicy")
    
    'View beschriften
    wbvPrivacyPolicy.LoadHtml(File.GetText(File.DirAssets, Starter.Language.Value("Datenschutzfile")))
    cbxPrivacyPolicy.Text = Starter.Language.Value("PolicyAllowed")
    cbxPrivacyPolicy.Checked = Starter.manager.getBoolean("IsPrivacyPolicyAllowed")
    mAllg.SetCBDrawable2FromFont(cbxPrivacyPolicy, Chr(0xF096), Chr(0xF046), 24 / mAllg.Fontscale, Colors.DarkGray)

    mAllg.SetFontsizePanel(DialogPanel)

    Wait For (sf) Dialog_Result (Result As Int)
    Starter.manager.setBoolean("IsPrivacyPolicyAllowed", cbxPrivacyPolicy.Checked)
 
    If Not(cbxPrivacyPolicy.Checked) Then
        Activity.Finish
    End If
End Sub
 

drgottjr

Expert
Licensed User
Longtime User
wbvPrivacyPolicy.LoadHtml(File.GetText(File.DirAssets, Starter.Language.Value("Datenschutzfile")))

is wbvPrivacyPolicy a webview by any chance? is it the view referred to in the error message?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
If it is not due to a misspelling error (double-check that wbvPrivacyPolicy is defined with the same name in the 'frmprivacypolicy' layout),
I'd try to add a Sleep(400) after the LoadLayout just to see if it makes any difference.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
yes, wbvPrivacyPolicy is a webview and the error message refers to it.
where is it initialized?
 
Upvote 0
D

Deleted member 103

Guest
If it is not due to a misspelling error (double-check that wbvPrivacyPolicy is defined with the same name in the 'frmprivacypolicy' layout),
I'd try to add a Sleep(400) after the LoadLayout just to see if it makes any difference.
Yes, I could try that, but then I should check whether this is the solution I want, and I can't, because I can't reproduce this error with my devices.
Normally the WebView should be available and initialized immediately after loading the layout, right?
Therefore I should know whether my code is actually correct or not.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Yes, I could try that, but then I should check whether this is the solution I want, and I can't, because I can't reproduce this error with my devices.
Normally the WebView should be available and initialized immediately after loading the layout, right?
Therefore I should know whether my code is actually correct or not.

Remove the webview, clean the project and then add a new webview back in.
 
Upvote 0
D

Deleted member 103

Guest
Strange error. If there is only a single report of this error then ignore it.
The error has been reported 10 times by 2 users.
1581241110506.png


I would change my code now, what do you mean? Does it make sense?
Or should I not pay attention to it, as you have already suggested?

B4X:
Private Sub ShowPrivacyPolicy
    Dim dialog As CustomLayoutDialog

    Dim sf As Object = dialog.ShowAsync("", "OK", "", "",Null, False)
    Wait For (sf) Dialog_Ready (DialogPanel As Panel)
    DialogPanel.LoadLayout("frmprivacypolicy")
    
    Dim pnl As Panel = DialogPanel.GetView(0)
    Dim wbv As WebView = pnl.GetView(0)
    Dim cbx As CheckBox = pnl.GetView(1)
    
    'View beschriften
    wbv.LoadHtml(File.GetText(File.DirAssets, Starter.Language.Value("Datenschutzfile")))
    cbx.Text = Starter.Language.Value("PolicyAllowed")
    cbx.Checked = Starter.manager.getBoolean("IsPrivacyPolicyAllowed")
    mAllg.SetCBDrawable2FromFont(cbx, Chr(0xF096), Chr(0xF046), 24 / mAllg.Fontscale, Colors.DarkGray)

'    wbvPrivacyPolicy.LoadHtml(File.GetText(File.DirAssets, Starter.Language.Value("Datenschutzfile")))
'    cbxPrivacyPolicy.Text = Starter.Language.Value("PolicyAllowed")
'    cbxPrivacyPolicy.Checked = Starter.manager.getBoolean("IsPrivacyPolicyAllowed")
'    mAllg.SetCBDrawable2FromFont(cbxPrivacyPolicy, Chr(0xF096), Chr(0xF046), 24 / mAllg.Fontscale, Colors.DarkGray)

    mAllg.SetFontsizePanel(DialogPanel)

    Wait For (sf) Dialog_Result (Result As Int)
    Starter.manager.setBoolean("IsPrivacyPolicyAllowed", cbx.Checked)
 
    If Not(cbx.Checked) Then
        Activity.Finish
    End If
End Sub
 
Upvote 0
D

Deleted member 103

Guest
Better to use B4XDialog.
The error happens while the layout is loaded. It looks like it failed to create WebView for some reason.

I tate it that your privacy policy layout has a webview inside of it, if so try adding Sleep(0) after loading the layout.
Thank you!
I will try one of these 2 suggestions. :)
 
Upvote 0

Nando

Member
Licensed User
Longtime User
If it helps anyone, I had the same problem (Object should first be initialized (WebView).).
I realized that I had uninstalled chrome from my device.
After I reinstalled it, the problem was solved.

Regards
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you'll be pleased to know that when you upgrade to android 10, you can, once again, remove chrome. until then, chrome controls webview, so you need it. as you discovered.
 
Upvote 0

Nando

Member
Licensed User
Longtime User
Thank you for the information drgottjr.:cool:

This morning the same problem came back and I had to do this... "Launch Play Store, start update of Android System Webview".

More information here: bugs.chromium
 
Upvote 0
Top