B4J Question Java Code Failing in stand alone package

MrKim

Well-Known Member
Licensed User
Longtime User
Reference this thread

This the code that fails in stand alone package:

B4X:
   Dim jo As JavaObject
   jo.InitializeStatic("java.awt.Toolkit")
   Dim toolkit As JavaObject = jo.RunMethod("getDefaultToolkit", Null)
   toolkit.RunMethod("beep", Null)

Basically the a B4XFloatTextField is expecting a certain range of keys. This is checked in the TextChanged event and if the key is not one of the expected keys the Beep Routine is called.
Old:, New: and S: are logs of .._TextChanged (Old As String, New As String), and New.SubString(New.Length - 1).

Below is the output when the app is run using run_debug.bat:

B4X:
C:\AndroidApps\B4X\PWDB\B4J\Objects\temp\build>cd bin

C:\AndroidApps\B4X\PWDB\B4J\Objects\temp\build\bin>java.exe @release_java_modules.txt --add-opens javafx.controls/com.sun.javafx.scene.control.skin=b4j -m b4j/b4j.example.main
*** mainpage: B4XPage_Created
*** mainpage: B4XPage_Appear
*** mainpage: B4XPage_Resize [mainpage]
ChangingText: false
Old:
NEW: d
S: d
b4xfloattextfield._tf_textchanged (java line: -1)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject (in module b4j) cannot access class sun.awt.windows.WToolkit (in module java.desktop) because module java.desktop does not export sun.awt.windows to module b4j
        at b4j/anywheresoftware.b4a.keywords.Common.CallSub4(Unknown Source)
        at b4j/anywheresoftware.b4a.keywords.Common.CallSubNew3(Unknown Source)
        at b4j/b4j.example.b4xfloattextfield._tf_textchanged(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
        at b4j/anywheresoftware.b4a.BA$1.run(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject (in module b4j) cannot access class sun.awt.windows.WToolkit (in module java.desktop) because module java.desktop does not export sun.awt.windows to module b4j
        at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
        ... 16 more
Caused by: java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject (in module b4j) cannot access class sun.awt.windows.WToolkit (in module java.desktop) because module java.desktop does not export sun.awt.windows to module b4j
        at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source)
        at java.base/java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at b4j/anywheresoftware.b4j.object.JavaObject.RunMethod(Unknown Source)
        at b4j/b4j.example.b4xmainpage._beep(Unknown Source)
        at b4j/b4j.example.b4xmainpage._cifra1_textchanged(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        ... 17 more
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0
Top