B4J Question [SOLVED] Unexpected event (missing RaiseSynchronousEvents)

PatrikCavina

Active Member
Licensed User
Hi to all,
I'm trying to wrap ObservableList object.
On Add, AddAll and SetAll methods, i receive this error:
B4X:
Waiting for debugger to connect...
Program started.
Unexpected event (missing RaiseSynchronousEvents): sizechanged_event
java.lang.Exception: Stack trace
    at java.lang.Thread.dumpStack(Thread.java:1333)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:194)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at anywheresoftware.b4j.object.JavaObject$1.invoke(JavaObject.java:237)
    at com.sun.proxy.$Proxy0.onChanged(Unknown Source)
    at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
    at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
    at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
    at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
    at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
    at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
    at javafx.collections.ModifiableObservableListBase.setAll(ModifiableObservableListBase.java:90)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    at b4j.example.observablelist._setall(observablelist.java:78)
    at b4j.example.main._appstart(main.java:110)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at b4j.example.main.start(main.java:38)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)

I added #RaisesSynchronousEvents but, maybe for my fault, it doesn't work.
Below snippet of code where i think there is a problem.
B4X:
#RaisesSynchronousEvents: SizeChanged_Event
#Event: Changed
Sub Class_Globals
    Private eName As String
    Private cBack As Object
    Private obsList As JavaObject
End Sub

Public Sub Initialize(EventName As String, CallBack As Object)
    eName = EventName
    cBack = CallBack

    Dim l As List
    l.Initialize
    obsList = ListToObservableList(l)
    SetListener(obsList)
End Sub

Private Sub ListToObservableList(l As List) As JavaObject
    Dim fxCollection As JavaObject
    fxCollection.InitializeStatic("javafx.collections.FXCollections")
    Dim joObservableList As JavaObject = fxCollection.RunMethod("observableArrayList", Array(l))
    Return joObservableList
End Sub

Private Sub SetListener(joObservableList As JavaObject)
    Dim e As Object = joObservableList.CreateEvent("javafx.collections.ListChangeListener", "SizeChanged", False)
    joObservableList.RunMethod("addListener", Array(e))
End Sub

Public Sub Add(Item As Object)
    obsList.RunMethod("add", Array(Item))
End Sub

Private Sub SizeChanged_Event (MethodName As String, Args() As Object) As Object
    CallSubDelayed(cBack, eName & "_Changed")
    Return True
End Sub
 
Top