简体   繁体   中英

JavaFX loading FXML causes warning and fails to load the file (skin/modena)

Situation

I'm trying to build a JavaFX App and for GUI I use SceneBuilder to produce fxml files for the different roots to use. Then I launch the App and at some point I'm trying to load some fxml file with new FXMLLoader(App.class.getResource("myFXML.fxml")).load() and set it as root on the scene on the stage.


Issue

99% of the times the loading has no problem at all and everything works as intended, but that 1% will fail and prevent the fxml loading without stopping the App but only throws the warning bellow.

WARNING: Caught 'java.lang.ClassCastException: class java.lang.String 
cannot be cast to class javafx.scene.paint.Paint (java.lang.String is in
module java.base of loader 'bootstrap'; javafx.scene.paint.Paint is in 
module javafx.graphics@18 of loader 'app')' while converting value for 
'-fx-background-color' from rule '*.list-view' in stylesheet 
jar:file:///C:/mysystem/.m2/repository/org/openjfx/javafx-controls/18/javafx-controls-18-win.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss

The fxml that causes it most of the time is the one with a ComboBox in it but i don't think this has to do with it since it happened anywhere.

Important the warning is not consistent as well, at the pre-last line instead of *.list-view other times says *.button as well, but i am doing the same action to test it.


Reproducing the Issue

Reproducing is not consistent at all, the warning is descriptive and seems that the problem is on a JavaFX file (mentioned in the warning) and not in something I wrote. Thus I can't find a consistent way to reproduce it or handle the exception or something.


Tried so far

  • Removing the ComboBox (just in case)
  • Searched the internet to find nothing about it
  • Re-installing JDK did nothing

Note

I know there is much more information I can provide that may help but I'm exhausted right now. Maybe will add with edit later on.

Long Story Short

I was doing the FXML loading ( new FXMLLoader(App.class.getResource("myFXML.fxml")).load() ) and scene.setRoot(...) on another Thread and not the FX Thread. So make sure with Platform.isFxApplicationThread(); (as mentioned in the comments) that the operation happens on the FX Thread to ensure expected behavior.


Important

The answer is not complete , it is a placeholder for anyone searching it currently and this resolves the issue.


Improvements

I will try as soon as possible to update the question with more information and reproducible example. Also I will with the help of the comments continue the research to find solid explanation for the issue. In the mean time feel free for edits or post new better answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM