Olá. Eu tentei criar um Alert do JavaFX com a seguinte estrutura:
try {
s = new ServerSocket(9581);
} catch (Exception e2) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Erro!");
alert.setHeaderText(null);
alert.setContentText("O programa já está em execução");
alert.showAndWait();
System.exit(1);
e2.printStackTrace();
}
Eu já trabalhei com Alert outras vezes sem problema algum, mas agora eu estou recebendo uma exceção que eu não entendo:
Exception in thread "main" java.lang.ExceptionInInitializerError
at javafx.scene.control.DialogPane.createContentLabel(DialogPane.java:167)
at javafx.scene.control.DialogPane.<init>(DialogPane.java:218)
at javafx.scene.control.Dialog.<init>(Dialog.java:506)
at javafx.scene.control.Alert.<init>(Alert.java:245)
at javafx.scene.control.Alert.<init>(Alert.java:223)
at com.tkfentreteniment.meusdados.start.Start.main(Start.java:23)
Caused by: java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:550)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
at javafx.scene.control.Control.<clinit>(Control.java:87)
... 6 more
Obs: Start.java:23 = Alert alert = new Alert(AlertType.ERROR);
Alguém aqui sabe me dizer o que eu fiz de errado?