Running some unit tests on class that contains a JavaFX alert, I implemented the following try-catch block:
try{
if(warning){
//CONSIDER: Make a generic alert call for any situation, pass args
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("User Warning");
alert.setHeaderText(null);
alert.setContentText("The following elements were not found for the code you are outputting and are printed, as is"
+ "\n\n" + errorList
+ "\n\n(This should be updated to Z000 format) ");
alert.showAndWait();
}}
//throws error when invoked from a non javaFX context
catch(IllegalStateException e){
System.out.println("The following elements were not found for the code you are outputting and are printed, as is"
+ "/n/n" + errorList
+ "/n/n(This should be updated to Z000 format)");
}
After making a top-level try-catch on the calling code that didn't fix it either.
Stack:
Exception in thread "main" java.lang.ExceptionInInitializerError
at javafx.scene.control.DialogPane.createContentLabel(DialogPane.java:166)
at javafx.scene.control.DialogPane.<init>(DialogPane.java:217)
at javafx.scene.control.Dialog.<init>(Dialog.java:478)
at javafx.scene.control.Alert.<init>(Alert.java:245)
at javafx.scene.control.Alert.<init>(Alert.java:223)
at gov.ornl.nstd.datatools.OutputFormatter.verifyAndNorm(OutputFormatter.java:385)
at gov.ornl.nstd.datatools.OutputFormatter.convert(OutputFormatter.java:218)
at gov.ornl.nstd.datatools.Testing.TestAllOutputs.main(TestAllOutputs.java:49)
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)
... 8 more
What are some ways to work around this?
What I'm getting from the error is that there is no JavaFX scene/stage to associate the Alert with, but I'm not sure how to deal with this.