B4J Question B4J Object in javascript

Jeanc161

Member
Licensed User
Longtime User
HI, it's been a while since i last login to the forum, and i now just restarted to work with B4X for a new contract so here is my question..

I know in B4A there is an object global B4A. that can be called to execute a function or sub in the b4A android program from the webcontrol in javascript.
Ex.. B4A.loadArticle(pageno, ArticleNo) and the execution will be passed to the android application currently running to execute the sub loadArticle with two parameters that are expected.
All and all this works great in B4A android but does not in B4J, is there and object like B4A that can be used in B4J to execute a function called from a javascript code inside and HTML file or data file object (wich i use the most) that can emulate the same thing using the webBrowser control in B4J to call the B4J object and execue a function inside te B4J program currently executed in windows.

And if not did someone knows a way around this that can execute a sub in B4J from the webcontrol that is used in B4J.

Thanks,

PS:It is nice to be back coding in B4X was not much work for the last year and a half, so got to go into the sauce and remember everything in B4J, B4A and B4I so many months of work ahaead..
 

FrostCodes

Active Member
Licensed User
You can take a look at my sample, it should be a starting point (You need Java 14 to run it).
 
Upvote 0

Jeanc161

Member
Licensed User
Longtime User
You can take a look at my sample, it should be a starting point (You need Java 14 to run it).

Hi,
I look at the sample and copy the code into the main of my project
Here is how it is organized
This is in app start sub
' loadWebView1 is the webview name that i use

Dim WebviewJo As JavaObject = loadWebview1.As(JavaObject)
Dim WebEngine As JavaObject = WebviewJo.RunMethodJO("getEngine",Null)

Dim currentInstance As JavaObject = Me
currentInstance.RunMethod("setBridge", Array(WebEngine))
... more stuff
End appStart sub

i put the java code at the end of the main module where i put all my java stuff in there as describe in your sample
i use the JDK14 and the javaobject 2.06 that i think is internal, the IDE version is 9.80 (64bits)

Question:
The thing that i don't understand is it can find getEngine in B4A object is this method been removed from the java version 2.06 or
my version of java is not up todate i don't understand why.
Can someone shed a little bit of light on this and can tell me if the javaobject is the right version for it
i'm in the process to update my IDE to the version 10.0 so that i can be up todate in the developement environment


Using the sample code i change a few things for my own environment but when i execute i got an error like

java.lang.RuntimeException: Method: getEngine not found in: anywheresoftware.b4a.objects.Timer
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at anywheresoftware.b4j.object.JavaObject.RunMethodJO(JavaObject.java:139)
at douanessn.essic.sn.main$ResumableSub_AppStart.resume(main.java:1155)
at douanessn.essic.sn.main._appstart(main.java:1087)

other stuff not relative to this error not important from the stack.
 
Upvote 0

FrostCodes

Active Member
Licensed User
Try this example, might be helpful but I don't know why the getEngine has issues


 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Nice to have you back. During your absence you may have missed certain updates. I would therefore first start by updating your Java environment first and then uninstalling the existing B4A and B4J environments and then really following the first time installation process step by step for a clean installation of B4J and B4A. You can then first test existing examples in B4J and, if this works well, then transfer them to B4A and test them.
If you still have problems, you can post a small program example using the code tags here.
 
Upvote 0
Top