B4J Question Pi3, JavaFx and SwiftButton

rdkartono

Member
Licensed User
Longtime User
When I added swiftbuttons to application, and ran it, It have error such below :
B4X:
Waiting for debugger to connect...
Program started.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by anywheresoftware.b4a.objects.B4XCanvas (file:/home/pi/tempjars/AsyncInput1) to field javafx.scene.canvas.GraphicsContext.path
WARNING: Please consider reporting this to the maintainers of anywheresoftware.b4a.objects.B4XCanvas
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Error occurred on line: 28 (buttonmenu2)
java.lang.ClassCastException: class b4j.example.swiftbutton cannot be cast to class javafx.scene.Node (b4j.example.swiftbutton is in unnamed module of loader 'app'; javafx.scene.Node is in module [email protected] of loader 'platform')
    at b4j.example.buttonmenu2._designercreateview(buttonmenu2.java:102)
    at b4j.example.main._appstart(main.java:105)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.intern
al.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.start(main.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(I
nvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    at java.base/java.lang.Thread.run(Thread.java:834)


My codes to create this buttons (CustomView XUI) :
B4X:
#DesignerProperty: Key: BooleanExample, DisplayName: Show Seconds, FieldType: Boolean, DefaultValue: True
#DesignerProperty: Key: TextColor, DisplayName: Text Color, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: Text color

Sub Class_Globals
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Private mBase As B4XView 'ignore
    Private xui As XUI 'ignore
    Private btnlist As List
End Sub

Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
    btnlist.Initialize
End Sub

'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    mBase = Base
    create_buttons
    Dim left As Int = 1dip
    Dim top As Int = 1dip
    Dim width As Int = (mBase.Width/2)-4dip
    Dim height As Int = (mBase.Height / 5)-4dip
    
    For ii = 0 To 4
        mBase.AddView(btnlist.Get(ii),left,top, width, height)
        top = top + height+1dip
    Next
    
    left = (mBase.Width/2)+1dip
    top = 1dip
    For ii = 5 To 9
        mBase.AddView(btnlist.Get(ii),left,top,width,height)
        top = top + height + 1dip
    Next
End Sub

Private Sub Base_Resize (Width As Double, Height As Double)
 
End Sub

Private Sub create_buttons
    For ii = 1 To 10
        Dim btn As SwiftButton = make_buttons($"Zone $2.0{ii}"$)
        btnlist.Add(btn)
    Next
End Sub

Private Sub make_buttons(textnya As String) As SwiftButton
    Dim btn As SwiftButton
    btn.Initialize(Me,"btn")
    Dim lbl As Label
    lbl.Initialize("")
    Dim props As Map
    props.Initialize
    props.Put("PrimaryColor",xui.Color_Green)
    props.Put("SecondaryColor",xui.Color_Blue)
    btn.DesignerCreateView(xui.CreatePanel(""),lbl,props)
    
    btn.xLBL.Text = textnya
    
    Return btn
End Sub

Any advice ?
 
Top