Android Question Why does this work in Debug but not release

Ph1lJ

Member
Licensed User
Longtime User
Hi Anyone

I modified this small app, I want to work with the returned html value from a controller - when I test the following in debug with a tablet, I get exactly what I'm looking for the index of 'analog' from the response html.

If I run it in release mode, it simply tells me that the app which I called 'http response' has stopped working

Can anyone help ??

I'm using B4A v5.5

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim WebViewExtras1 As WebViewExtras
Dim WebView1 As WebView
Private Label1 As Label
Private Button1 As Button
Private Button2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")

' add the B4A javascript interface to the WebView
WebViewExtras1.addJavascriptInterface(WebView1, "B4A")

' now load a web page
'WebView1.LoadUrl("http://10.110.214.35/arduino/analog/0")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
' Now that the web page has loaded we can get the page content as a String

' see the documentation http://www.b4x.com/forum/additional...al-updates/12453-webviewextras.html#post70053 for details of the second parameter callUIThread

Dim Javascript As String
Javascript="B4A.CallSub('ProcessHTML', false, document.documentElement.outerHTML)"


'Log("PageFinished: "&Javascript)
WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub

Sub ProcessHTML(Html As String)
' This is the Sub that we'll get the web page to send it's HTML content to

' Log may truncate a large page so you'll not see all of the HTML in the log but the 'html' String should still contain all of the web page HTML
Label1.Text = Html.IndexOf("analog")
Log("here")

End Sub

Sub Button1_Click
WebView1.LoadUrl("http://10.110.214.35/arduino/analog/0")
End Sub

Sub Button2_Click
WebView1.LoadUrl("http://10.110.214.35/arduino/analog/1")
End Sub
 

DC1

Member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Are you connected in USB debug mode? This will allow you to see the logs in release mode.

So I did as you requested, here is the response :- (used same code as post #1)

[code]
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_processhtml (java line: 392)
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:5593)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1099)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:4303)
at android.view.View.invalidate(View.java:11263)
at android.view.View.invalidate(View.java:11218)
at android.widget.TextView.checkForRelayout(TextView.java:7441)
at android.widget.TextView.setText(TextView.java:4300)
at android.widget.TextView.setText(TextView.java:4137)
at android.widget.TextView.setText(TextView.java:4112)
at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:43)
at ph1lj.app.htmlr.main._processhtml(main.java:392)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at uk.co.martinpearman.b4a.webviewextras.WebViewExtras$1B4AJavascriptInterface.CallSub(WebViewExtras.java:71)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:325)
at android.webkit.WebViewCore.loadUrl(WebViewCore.java:3333)
at android.webkit.WebViewCore.access$2300(WebViewCore.java:76)
at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:1092)
at java.lang.Thread.run(Thread.java:856)
** Activity (main) Pause, UserClosed = true **
[/code]

Really need someones help
 
Upvote 0

Ph1lJ

Member
Licensed User
Longtime User
Ok tried this
but doesn't call Process_HTML2

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
  
   Dim WebViewExtras1 As WebViewExtras
   Dim WebView1 As WebView
    Private Label1 As Label
    Private Button1 As Button
    Private Button2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
  
   '   add the B4A javascript interface to the WebView
   WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
  
   '   now load a web page
   'WebView1.LoadUrl("http://10.110.214.35/arduino/analog/0")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
   '   Now that the web page has loaded we can get the page content as a String
  
   '   see the documentation http://www.b4x.com/forum/additional-libraries-classes-official-updates/12453-webviewextras.html#post70053 for details of the second parameter callUIThread
  
   Dim Javascript As String
   'Javascript="B4A.CallSub('Process_HTML', false, document.documentElement.outerHTML)"
    Javascript="B4A.CallSubDelayed('Process_HTML2', false, document.documentElement.outerHTML)"

   'Log("PageFinished: "&Javascript)
   WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub

'Sub Process_HTML(Html As String)
'   '   This is the Sub that we'll get the web page to send it's HTML content to
'  
'   '   Log may truncate a large page so you'll not see all of the HTML in the log but the 'html' String should still contain all of the web page HTML
'   Label1.Text = Html.IndexOf("analog")
'   Log("here")
'  
'End Sub


Sub Process_HTML2(Html As String)
   '   This is the Sub that we'll get the web page to send it's HTML content to
  
   '   Log may truncate a large page so you'll not see all of the HTML in the log but the 'html' String should still contain all of the web page HTML
   Label1.Text = Html.IndexOf("analog")
   Log("here")
  
End Sub
    

Sub Button1_Click
    WebView1.LoadUrl("http://10.110.214.35/arduino/analog/0")
End Sub

Sub Button2_Click
    WebView1.LoadUrl("http://10.110.214.35/arduino/analog/1")
End Sub

not sure if that correct
 
Upvote 0

DC1

Member
Licensed User
Longtime User
Great that has fixed it, can you explain why it was ok in debug - just curious

Thanks for your support
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
I had the same issue... Runs in debug, not in release. Using in-line Java...

Seems debug allowed my app to proceed (assuming permissions) but not in release...

added to manifest:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

Now release works!

Found this issue with explanation from posts above (using USB debugging)...

Some day I hope to be an expert in Java.
Only then will I truly appreciate how Erel (and other fine contributors) relieve us from these coding complexities.

Thanks so much... (some) hair is returning to the top of my head.
 
Upvote 0
Top