Hello,
I am facing a crash when using WebViewAssetLoader with WebViewClient.ShouldInterceptRequest.
I load local HTML files (unzipped previously) from File.DirInternal using:
Initialization:
When I exit the Activity (or it goes to background), the app crashes with:
java.lang.NullPointerException: Attempt to invoke virtual method
'boolean anywheresoftware.b4a.AbsObjectWrapper.IsInitialized()' on a null object reference
at uk.co.martinpearman.b4a.webkit.DefaultWebViewClient$1.shouldInterceptRequest(...)
I am facing a crash when using WebViewAssetLoader with WebViewClient.ShouldInterceptRequest.
Scenario:
I load local HTML files (unzipped previously) from File.DirInternal using:
B4X:
WebView1.LoadUrl(WebViewAssetLoader1.InternalPathUrl & "/exp/" & exp)
B4X:
WebViewAssetLoader1.Initialize(Application.PackageName)
WebViewEx.Initialize(WebView1)
WebViewClient.Initialize("WebViewClient")
WebViewEx.SetWebViewClient(WebViewClient)
WebViewEx.JavaScriptEnabled = True
Events:
B4X:
Private Sub WebViewClient_PageFinished(Url As String)
If Url.StartsWith(WebViewAssetLoader1.AssetPathUrl) Then
ToastMessageShow("Page loaded from DirAsset", True)
Else If Url.StartsWith(WebViewAssetLoader1.InternalPathUrl) Then
ToastMessageShow("Page loaded from DirInternal", True)
Else If Url.StartsWith(WebViewAssetLoader1.ResourcesPathUrl) Then
ToastMessageShow("Page loaded from Resources", True)
Else
ToastMessageShow("Page loaded from internet", True)
End If
End Sub
Private Sub WebViewClient_ShouldInterceptRequest(Url As String) As WebResourceResponse
Log("URL: " & Url)
Dim Response As WebResourceResponse
Dim ResponseReceived As WebResourceResponse
Try
ResponseReceived = WebViewAssetLoader1.ShouldInterceptRequest(Url)
If Not(ResponseReceived = Null) And ResponseReceived.IsInitialized Then
Response.Initialize(ResponseReceived.GetMimeType, ResponseReceived.GetEncoding, ResponseReceived.GetData)
Return Response
End If
Catch
Log("URL not found: " & Url)
End Try
Return Null
End Sub
Problem:
When I exit the Activity (or it goes to background), the app crashes with:java.lang.NullPointerException: Attempt to invoke virtual method
'boolean anywheresoftware.b4a.AbsObjectWrapper.IsInitialized()' on a null object reference
at uk.co.martinpearman.b4a.webkit.DefaultWebViewClient$1.shouldInterceptRequest(...)