B4J Question Problem with openjdk 19.x

kpmais

Member
Licensed User
Longtime User
Hi everyone.
To convert centimeters to pixels, I use the following routine:

B4X:
Private Sub GetPixelProCm As Int

    Dim jo As JavaObject
    jo.InitializeStatic("java.awt.Toolkit")
    jo = jo.RunMethod("getDefaultToolkit",Null)
    Return Floor(jo.RunMethod("getScreenResolution",Null)/2.18)

End Sub

This works fine with OpenJDK 14.x.
However, with OpenJDK 19.x, I get the following error when running:
java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class sun.awt.windows.WToolkit (in module java.desktop) because module java.desktop does not export sun.awt.windows to unnamed module @6224ccc0

at

B4X:
 jo.RunMethod("getScreenResolution",Null)

I have not found any indication that the awt.toolkit has changed in openjdk 19.x.

Can anyone help me?
Many thanks to the readers.
 
Add (Tested in Java 23)
Code:
    #VirtualMachineArgs:  --add-exports java.desktop/sun.awt.windows=ALL-UNNAMED
 
Last edited:
Upvote 1
C'est formidable !!!
Thank you very much. It works!!! :-)

I'll have to get into this topic.
Thanks again.
 
Upvote 0
Sorry, the joy is only partial.
It runs fine in debug and release.
However, when I produce a standalone app, the error occurs again. I'm using OpenJDK 19.x here as well.
I'll try a higher Java version.
 
Upvote 0
just add the similar command to the packager too (Steve beat me to it)
 
Upvote 0
Thanks again to both of you.
It works now :-).

But why is the assignment "=b4j" and not "=ALL-UNNAMED"?
I'm currently puzzling over that.
 
Upvote 0
Back
Top