Java exception using WebViewExtras

Cableguy

Expert
Licensed User
Longtime User
I am gettng this exeption, and don't quite understand it


B4X:
B4A.CallSub('LoginSucess',false,document.snd.name.value = 'cableguy', document.snd.password.value = 'xxxxxxxxx', document.forms['snd'].submit())





java.lang.Exception: Sub loginsucess signature does not match expected signature.
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:107)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:89)
   at uk.co.martinpearman.b4a.webviewextras.WebViewExtras$1B4AJavascriptInterface.CallSub(WebViewExtras.java:84)
   at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
   at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
   at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:246)
   at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1999)
   at android.webkit.WebViewCore.access$1400(WebViewCore.java:53)
   at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1123)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:199)
   at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:127)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:156)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:89)
   at uk.co.martinpearman.b4a.webviewextras.WebViewExtras$1B4AJavascriptInterface.CallSub(WebViewExtras.java:84)
   at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
   at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
   at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:246)
   at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1999)
   at android.webkit.WebViewCore.access$1400(WebViewCore.java:53)
   at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1123)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:130)
   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:674)
   at java.lang.Thread.run(Thread.java:1019)
java.lang.Exception: Sub loginsucess signature does not match expected signature.

Seems like my sub should be:

Sub LoginSucess ( ..... )

But I just don't know what to put within the backets!!
 

warwound

Expert
Licensed User
Longtime User
Hi.

I think (one or more of) the parameters you are passing to CallSub are NOT Strings...

B4X:
B4A.CallSub('LoginSucess', false, document.snd.name.value='cableguy', document.snd.password.value='xxxxxxxxx', document.forms['snd'].submit())

document.snd.name.value='cableguy' and document.snd.password.value='xxxxxxxxx' will assign values to your form and i think result in String values being passed to CallSub.

However document.forms['snd'].submit() will submit the form but not result in a String value being passed to Callsub.

Martin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi.

I think (one or more of) the parameters you are passing to CallSub are NOT Strings...

B4X:
B4A.CallSub('LoginSucess', false, document.snd.name.value='cableguy', document.snd.password.value='xxxxxxxxx', document.forms['snd'].submit())

document.snd.name.value='cableguy' and document.snd.password.value='xxxxxxxxx' will assign values to your form and i think result in String values being passed to CallSub.

However document.forms['snd'].submit() will submit the form but not result in a String value being passed to Callsub.

Martin.

Exactly, that's why I dont understand why this exception is thrown...!
Iexpect no result from the statements I used, unless the Submit() reurns a boolean, wich I have not tested yet...
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

I just put together a simple form and tried to get this value:

B4X:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<?php
   if(isset($_GET['value1'])){
      $myValue=$_GET['value1'];
   } else {
      $myValue="No value set";
   }
?>
</head>

<body>
<div>
   <form id="testForm" action="" method="get" onsubmit="document.forms.testForm.value1.value=typeof (document.forms.testForm.submit())">
      <input type="text" value="<?php echo $myValue; ?>" name="value1" />
      <input type="submit" value="Submit" />
   </form>
</div>
</body>
</html>

typeof (document.forms.testForm.submit()) returns undefined.

Martin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
One way of "solving" this issue, would be to be able to inject WITHOUT calling a B4A sub...Passing only the JScript strings...
This would be implemented as a new method , of course...
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
But what's stopping you from calling 'LoginSucess' with the exact values you require?

In javascript numbers can easily be converted to strings.

Are you just trying to cram two things into a single javascript statement?

You could set the form values and submit the form using javascript and then use the B4A WebView Event 'OverrideUrl' to detect when the page has submitted and the next page has been requested...

Explain in a bit more detail - i'm sure there's a simple way to do it!

Martin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I was trying to use the 3 parameters option, to inject the form's values, and force the form to submit...I do not expect a return value from it, but I could use the event to update a label, but can live without it.

I will try to seperate the two and check if it works.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
So I have managed to bypass the exception alert/message...

My sub is now as follows:
B4X:
WebSettings.setSaveFormData(WebView1, False)
         WebSettings.setSavePassword(WebView1, False)
         WebSettings.setLoadsImagesAutomatically(WebView1, False)   
         'Inject Username done
         'Inject Password done
         'Inject Auto-Submit done, but with an exception
         Script = "B4A.CallSub('',false,document.snd.name.value = '" & Main.PrefManager.GetString("UserName")&"')"
         Log(Script)
         WebExtras.executeJavascript(WebView1,Script)
         '---------------------
         Script = "B4A.CallSub('',false,document.snd.password.value = '" & Main.PrefManager.GetString("PassWord")&"')"
         Log(Script)
         WebExtras.executeJavascript(WebView1,Script)
         '---------------------
         Script = "B4A.CallSub('',false,document.snd.submit())"
         Log(Script)
         WebExtras.executeJavascript(WebView1,Script)

All the JScript are called in order, so the Login is successfull, BUT, en the Submit script is executed, the screen goes black for a few seconds, and then, when the submit finishes, the page/screen is shown correctly...

How can I prevent this behaviour? (the screen going black)

EDIT:

Interesting finding...If I hide (visible = False) the webview, get the described behaviour...BUT, if I keep it visible, even that only 10x10 pixels, and behind another view, thus making it invisible, The "twich" efect is very minimized, although not completly eliminated...
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi again.

I'm not sure if you really need to add the "B4A.CallSub()" to the javascript - especially if you're not actually calling a B4A Sub.

B4X:
WebSettings.setSaveFormData(WebView1, False)
WebSettings.setSavePassword(WebView1, False)
WebSettings.setLoadsImagesAutomatically(WebView1, False)   
'Inject Username done
'Inject Password done
'Inject Auto-Submit done, but with an exception
Script = "document.snd.name.value = '" & Main.PrefManager.GetString("UserName")&"'"
Log(Script)
WebExtras.executeJavascript(WebView1,Script)
'---------------------
Script = "document.snd.password.value = '" & Main.PrefManager.GetString("PassWord")&"'"
Log(Script)
WebExtras.executeJavascript(WebView1,Script)
'---------------------
Script = "document.snd.submit()"
Log(Script)
WebExtras.executeJavascript(WebView1,Script)

Whether that will fix the black screen or not...
Do you mean the WebView goes black or that the entire Activity goes black?

If you use WebViewExtras to call a B4A Sub that does not exist then the library should return a String error message to the javascript.

For example:

B4X:
alert(B4A.CallSub("NonExistentSub", false))

That should pop up an alert dialog with a message:

JavascriptInterface error: NonExistentSub does not exist

(Actually you'll not get an alert dialog unless you add the WebChromeClient to your WebView).

So your javascript sets the forms values or submits the form and tries to execute the 3 error messages as javascript, the equivalent of:

B4X:
WebExtras.executeJavascript(WebView1, "JavascriptInterface error: does not exist")
[code]

Where the non existent Sub name is "".

Add a WebChromeClient to your WebView and look at the Activity log - you should see something like a javascript syntax error reported i'd guess.

Martin.
 
Upvote 0
Top