Today I have something, which should be a common task, but somehow I am getting Exceptions for it. I have the following code:
public class ExampleScene extends Scene {
public ExampleScene(Parent parent) {
super(parent,Variables.width,Variables.height);
}
public static Parent fill() {
HBox gp = new HBox();
gp.getChildren().add(new Label("hi"));
return gp;
}
}
I'm calling them like this:
Parent par = ExampleScene.fill();
ExampleScene example = new ExampleScene(par);
But this produces the following exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at de.rrcomtech.basicgui.test.ExampleScene.fill(ExampleScene.java:20)
at de.rrcomtech.basicgui.test.startASimpleWindow.main(startASimpleWindow.java:18)
Caused by: java.lang.IllegalStateException: Toolkit not initialized
at javafx.graphics/com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:396)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:673)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:635)
at javafx.controls/javafx.scene.control.Control.<clinit>(Control.java:99)
... 2 more
The marked line is
gp.getChildren().add(new Label("hi"));
I cannot understand where is the fault in my code.