Java Question B4J String cannot be converted to ActionEvent

moster67

Expert
Licensed User
Longtime User
Hope this is the right section...

I'm playing around with B4J and trying to wrap a basic test library.

In my layout, I have a button but when trying to compile so I can call my method through my wrapper, I get an error saying that "String cannot be converted to ActionEvent". When I compile I get this error:

B4X:
B4J version: 4.70
Parsing code.    (0.00s)
Compiling code.    (0.03s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    Error
B4J line: 39
ocv.startCamera(button1_Action)
javac 1.8.0_66
src\b4j\example\main.java:93: error: incompatible types: String cannot be converted to ActionEvent
_ocv.startCamera((javafx.event.ActionEvent)(_button1_action()));
                                           ^
1 error

In my wrapper I have this method:
B4X:
public void startCamera(ActionEvent event){//do something}

I tried doing this in my B4J-code:
B4X:
Sub button1_Action
    ocv.startCamera(button1_Action)
End Sub

but it does not work.

So in B4j, what shall I pass as a parameter for my startCamera-method which takes "ActionEvent event" as an argument?

Related question: I tried both with the Internal designer and SceneBuilder but got same result. When wrapping, are there any differences to take into consideration when using the Internal Designer or is it fully compatible with SceneBuilder?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is exactly like in B4A. You need to pass the event name (string) and call ba.raiseEvent to raise the event.

B4X:
public void startCamera(BA ba, String EventName) {
 ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul) + "_action", ...);
}

You don't need to test it with scene builder. Scene builder is deprecated and is only kept for backwards compatibility.
 
Top