B4J Question how can i import classes from .jar with JavaObject ?

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
hi everyone !
i am using LuaJ .jar in my application .

how can i convert this >
B4X:
import org.luaj.vm2.*;
    import org.luaj.vm2.lib.jse.*;

    Globals globals = JsePlatform.standardGlobals();
    LuaValue chunk = globals.load("print 'hello, world'");
    chunk.call();

to B4J using JavaObject ?

i had used >
B4X:
jo.InitializeStatic("org.luaj.vm2.*")

jo.InitializeStatic("org.luaj.vm2.lib.jse.*")

but i get this error >

java.lang.ClassNotFoundException: org$luaj$vm2
 

Daestrum

Expert
Licensed User
Longtime User
To use javaobject how you want, you will need to know the class names within org.luaj.vm2 and org.luaj.vm2.lib.jse.

You are trying to assign a package name with a wild card to a javaobject, this will not work as you have to assign a class to the javaobject.

The first line of your code above code would translate to something like :
B4X:
...
Dim jsePlatform As JavaObject
Dim globals As JavaObject
…
jsePlatform.InitializeNewInstance("org.luaj.vm2.lib.jse.JsePlatform",null)
globals = jsePlatform.RunMethod("standardGlobals",null)
…
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
To use javaobject how you want, you will need to know the class names
That begs the question: how can one find the class names (and params) other than begging the author for some full documentation on it's use (which is often hard to obtain). De-compile the jar perhaps? Try and figure it out from there?

I have often wondered how - when using JavaObject - what to call, params and other requirements...
Samples provided (by Erel and others) give specific based on question... Where in the heck did they get that knowledge?
They make it seem so simple...

Thanks
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
In the case above I simply googled "org.luaj.vm2 api" which returned the Javadoc for the package. This showed the classes within each of the package names.

The class Javadoc shows the methods , their return types and required parameters.
 
Upvote 0
Top