I am developing a JavaFX application which uses the Apache Felix OSGi framework. I have an issue with firing custom events. Whenever I try to fire a custom event, the exception java.lang.IllegalArgumentException: EventType "ADD_SENSOR" with parent "EVENT" already exists
(stacktrace is shown below) is thrown.
Caused by: java.lang.IllegalArgumentException: EventType "ADD_SENSOR"with parent "EVENT" already exists
at javafx.event.EventType.register(EventType.java:186)
at javafx.event.EventType.<init>(EventType.java:128)
at swt6.componentmanager.gui.event.AddSensorEvent.<clinit>(AddSensorEvent.java:8)
The code firing the event is shown below.
private void onAddSensor(ActionEvent event) {
AddSensorEvent addSensorEvent = new AddSensorEvent(
this.typeComboBox.getValue(),
this.nameInput.getText(),
this.descriptionInput.getText()
);
this.addButton.fireEvent(addSensorEvent);
// close the window
((Stage) this.getScene().getWindow()).close();
}
The class AddSensorEvent
, which also manages the EventType
instance via a public static final
field, is illustrated below, too.
public class AddSensorEvent extends Event {
public static final EventType<AddSensorEvent> ADD_SENSOR_EVENT_TYPE =
new EventType<>(EventType.ROOT, "ADD_SENSOR");
private final SensorFactory sensorFactory;
private final String sensorName;
private final String sensorDescription;
public AddSensorEvent(SensorFactory sensorFactory, String sensorName, String sensorDescription) {
super(ADD_SENSOR_EVENT_TYPE);
this.sensorFactory = sensorFactory;
this.sensorName = sensorName;
this.sensorDescription = sensorDescription;
}
public SensorFactory getSensorFactory() {
return this.sensorFactory;
}
public String getSensorName() {
return this.sensorName;
}
public String getSensorDescription() {
return this.sensorDescription;
}
}
The application is a port of an application using the Java module system, which was introduced in Java 9, and it works fine when using the module system.
I tried following this, this and this issues, but none of the provided solutions worked for me.
Thank you for your help!