简体   繁体   中英

Gluon Mobile - fxml file “Location is not set”

I want to implement javafx app both on desktop and android. When I try load fxml file:

FXMLLoader loader = new FXMLLoader(getClass().getResource("ProjectSetup.fxml")); Parent root = loader.load();

I am getting an error: java.lang.IllegalStateException: Location is not set. I tried putting it in Resources(Main), Resources(Desktop),Source Packages(Java).

Example

[1]

None of it worked.

Where should I put "ProjecSetup.fxml" to get it working?

The appropriate location for fxml files is src/main/resources/yourpackage . If the class which is calling getResource() is not located in the same package as the referenced fxml.file, ie src/main/yourpackage , you have to use an aboslute path: fxmlLoader(getClass().getResource("/yourpackage/ProjectSetup.fxml") . Pay attention to the leading slash

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