I am developing a JavaFX application which uses the Apache Felix OSGi framework. My issue is that when trying to register for a custom event the exception shown below is thrown.
org.apache.karaf.shell.support.MultiException: Error executing command on bundles:
...
Caused by: java.lang.NoClassDefFoundError: Could not initialize class swt6.componentmanager.gui.event.RemoveSensorEvent
at swt6.componentmanager.gui.ComponentManagerGui.createSensorView(ComponentManagerGui.java:170) ~[?:?]
at swt6.componentmanager.gui.ComponentManagerGui.createSensorActuatorContainer(ComponentManagerGui.java:159) ~[?:?]
at swt6.componentmanager.gui.ComponentManagerGui.createRootContainer(ComponentManagerGui.java:91) ~[?:?]
at swt6.componentmanager.gui.ComponentManagerGui.lambda$start$0(ComponentManagerGui.java:62) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428) ~[?:?]
at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427) ~[?:?]
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96) ~[?:?]
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) ~[?:?]
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277) ~[?:?]
... 1 more
The code for registering for the custom event is shown below, too.
private Node createSensorView() {
var container = new VBox();
container.getChildren().add(JavaFXUtil.createHeading("Sensors"));
var sensorTable = new SensorsTable(this.sensors);
sensorTable.addEventHandler(
RemoveSensorEvent.REMOVE_SENSOR_EVENT_TYPE,
this::onRemoveSensor
);
container.getChildren().add(sensorTable);
return container;
}
The code of the class RemoveSensorEvent
is also illustrated below.
package swt6.componentmanager.gui.event;
import javafx.event.Event;
import javafx.event.EventType;
import swt6.sensor.Sensor;
public class RemoveSensorEvent extends Event {
public static final EventType<RemoveSensorEvent> REMOVE_SENSOR_EVENT_TYPE =
new EventType<>(Event.ANY, "REMOVE_SENSOR");
private final Sensor sensor;
public RemoveSensorEvent(Sensor sensor) {
super(REMOVE_SENSOR_EVENT_TYPE);
this.sensor = sensor;
}
public Sensor getSensor() {
return this.sensor;
}
}
The bundle which contains the JavaFX code has the following package layout; all these packages are located in the same bundle:
swt6.componentmanager.gui
ComponentManagerGui.java
swt6.componentmanager.gui.event
RemoveSensorEvent.java
swt6.componentmanager.gui.component
swt6.componentmanager.gui.viewmodel
As RemoveSensorEvent
is part of the package swt6.componentmanager.gui.event
, which is located within the same bundle as the code invoking it (swt6.componentmanager.gui.ComponentManagerGui.java
), there should not be any issue with loading the class definition; for instance, classes located in swt6.componentmanager.gui.component
and swt6.componentmanager.gui.viewmodel
can be accessed from swt6.componentmanager.gui
with no problems. Does this have something to do with JavaFX trying to access RemoveSensorEvent
using reflection?