B4J Question B4JPackager11 Exception

micro

Well-Known Member
Licensed User
Hi to all
I have thi exception when i start the program in standalone packager
B4X:
funzself._sound (java line: -1)
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.Prog.funzself._sound(Unknown Source)
    at b4j/b4j.Prog.funzself$ResumableSub_button__MouseReleased.resume(Unknown Source)
    at b4j/b4j.Prog.funzself._button__mousereleased(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.raiseEvent(Unknown Source)
    at b4j/anywheresoftware.b4j.objects.NodeWrapper$3.handle(Unknown Source)
    at b4j/anywheresoftware.b4j.objects.NodeWrapper$3.handle(Unknown Source)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.base/javafx.event.Event.fireEvent(Unknown Source)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Unknown Source)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Unknown Source)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Unknown Source)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(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)

This is the sub
B4X:
Sub Sound
    Dim jo As JavaObject
    jo.InitializeStatic("java.awt.Toolkit")
    Dim toolkit As JavaObject = jo.RunMethod("getDefaultToolkit", Null)
    toolkit.RunMethod("beep", Null)
End Sub

what should i put in PackagerProperty

#PackagerProperty: ?

Thanks
 

Daestrum

Well-Known Member
Licensed User
I tried lots of combinations but was unable to get it to open the module to the program.
Funny thing is , if you call it via inline java you dont get the error as it doesn't use reflection. (I got no beep, but probably my computer, it doesn't beep when I turn it on)
 
Upvote 0

micro

Well-Known Member
Licensed User
Hi daestrum
i tried with inline java, as also suggested by erel in another thread but the error is the same
B4X:
Sub Beep
    Dim jo As JavaObject = Me
    jo.RunMethod("beep", Null)
End Sub

#if Java
public static void beep() {
    java.awt.Toolkit.getDefaultToolkit().beep();
}
#End If

Thanks
 
Upvote 0

micro

Well-Known Member
Licensed User
I solved the beep problem using the jaudioclip library
but now another exception when click on button.
I have a series of buttons grouped under a single event
B4X:
Private Sub button__MouseMoved (EventData As MouseEvent)
    Dim bt As Button = Sender
    bt.MouseCursor = fx.Cursors.HAND
End Sub

Private Sub button__MousePressed (EventData As MouseEvent)
    Dim bt As Button = Sender
    bt.Alpha = 0.8
End Sub

Private Sub button__MouseReleased (EventData As MouseEvent)
    If beep Then Sound
    Dim bt As Button = Sender
    bt.Alpha = 1.0
    If EventData.ClickCount > 1 And bt.Tag = "m2" Then
    ......
    ......
This's the Exception
B4X:
funzself$ResumableSub_button__MouseReleased.resume (java line: -1)
java.lang.RuntimeException: Object should first be initialized (Button).
    at b4j/anywheresoftware.b4a.AbsObjectWrapper.getObject(Unknown Source)
    at b4j/anywheresoftware.b4j.objects.NodeWrapper.getTag(Unknown Source)
    at b4j/b4j.GestWeight.funzself$ResumableSub_button__MouseReleased.resume(Unknown Source)
    at b4j/b4j.GestWeight.funzself._button__mousereleased(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.raiseEvent(Unknown Source)
    at b4j/anywheresoftware.b4j.objects.NodeWrapper$3.handle(Unknown Source)
    at b4j/anywheresoftware.b4j.objects.NodeWrapper$3.handle(Unknown Source)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.base/javafx.event.Event.fireEvent(Unknown Source)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Unknown Source)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Unknown Source)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Unknown Source)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(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)
 
Upvote 0

Daestrum

Well-Known Member
Licensed User
This was the inline I used
B4X:
#if java
import java.awt.Toolkit;
public static void doIt(){
    Toolkit.getDefaultToolkit().beep();
}
#End If
 
Upvote 0

micro

Well-Known Member
Licensed User
Excuse me guys but switching from java8 to java11 is causing me problems
the previous problem on button initialisation is always caused by the beep,
strangely going back to this solution now it works
B4X:
Sub Beep
    Dim jo As JavaObject = Me
    jo.RunMethod("beep", Null)
End Sub

#if Java
public static void beep() {
    java.awt.Toolkit.getDefaultToolkit().beep();
}
#End If
so i confirm this code works with B4jPackager11
I eliminated calls to JfxDialog with B4xDialog and other code that only worked on java8 and now all work fine.
switch to java11 successful!
Thanks everyone for the support
 
Upvote 0

micro

Well-Known Member
Licensed User
:(
An extra function that I had not tried does not work, it only works in debug.
The program now compiled with java11 has an additional function that starts a websocket (ABMaterial program compiled with java8)
B4X:
Sub Runsocketws
    'Return
    Dim javaexe As String
    javaexe = File.Combine(GetSystemProperty("java.home", ""), "bin/java")
    shws.Initialize("shws", javaexe, Array ("-jar", "GW_Web.jar"))
    shws.WorkingDirectory = File.DirApp & "\GW_Web"
    socketopen = True
    shws.Run(-1)
    NotificaShow("", "Web Socket avviato!", "none", 2000, True)
End Sub
Sub shws_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success = False Or StdErr.IndexOf("Unable to access") > -1 Then
        socketopen = False
        NotificaShow("", "Web Socket chiuso!", "none", 2000, True)
    End If
End Sub
I have added this
B4X:
#PackagerProperty: AdditionalModuleInfoString = uses org.eclipse.jetty.websocket.common.RemoteEndpointFactory;
but not work
this in log
B4X:
org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.1.155:9999 refused
    at b4j/org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(Unknown Source)
    at b4j/org.apache.http.impl.conn.AbstractPoolEntry.open(Unknown Source)
    at b4j/org.apache.http.impl.conn.AbstractPooledConnAdapter.open(Unknown Source)
    at b4j/org.apache.http.impl.client.DefaultRequestDirector.execute(Unknown Source)
    at b4j/org.apache.http.impl.client.AbstractHttpClient.execute(Unknown Source)
    at b4j/org.apache.http.impl.client.AbstractHttpClient.execute(Unknown Source)
    at b4j/org.apache.http.impl.client.AbstractHttpClient.execute(Unknown Source)
    at b4j/anywheresoftware.b4a.http.HttpClientWrapper.executeWithTimeout(Unknown Source)
    at b4j/anywheresoftware.b4a.http.HttpClientWrapper.access$0(Unknown Source)
    at b4j/anywheresoftware.b4a.http.HttpClientWrapper$ExecuteHelper.run(Unknown Source)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

Where is the problem?
Thanks
 
Upvote 0

micro

Well-Known Member
Licensed User
Hi
I recompiled the additional jar of ABMaterial (GW_Web.jar) with java11 and I set the Path of JAVA_HOME and now work because
the jar, points to the right path.
I tried to point to the pagkager java (into build) by setting the right path but not work.
Thanks
 
Upvote 0

OliverA

Expert
Licensed User
#PackagerProperty: ?
Late to the party, but the answer is/was
B4X:
#PackagerProperty: VMArgs = --add-opens java.desktop/sun.awt.windows=b4j
 
Upvote 3
Solution
Top