具有父级“ EVENT”的事件类型“ ADD_SENSOR”已存在

时间:2019-03-07 11:51:54

标签: java javafx osgi openjfx

我正在开发一个使用Apache Felix OSGi框架的JavaFX应用程序。我在触发自定义事件时遇到问题。每当我尝试触发自定义事件时,都会引发异常java.lang.IllegalArgumentException: EventType "ADD_SENSOR" with parent "EVENT" already exists(堆栈跟踪如下所示)。

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)

触发事件的代码如下所示。

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();
}

下面也说明了类AddSensorEvent,该类也通过EventType字段管理public static final实例。

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;
    }
}

应用程序是Java 9中引入的使用Java模块系统的应用程序的端口,并且在使用模块系统时可以正常工作。

我尝试关注thisthisthis问题,但是所提供的解决方案都不适合我。

谢谢您的帮助!

0 个答案:

没有答案