简体   繁体   中英

Compile JavaFx application in IntelliJ getResources() returns null

When running the app inside IntelliJ, everything works fine.

When building artifacts, the reference to *.fxml files are not found and return when calling getClass().getResources("/path/to/fxml/file.fxml")

Executing *.jar or *.exe throws a NullPointerException: Location is not set.

How can this be resolved?

  1. In IntelliJ, go to Project Structure -> Artifacts
  2. In Output Layout Tab, click the + Icon and select Directory Content
  3. Select your resource directory

If this doesnt work, inside your project in IntelliJ, right-click on your resource directory and select Mark Directory As.. -> Mark as Resource Root

Make sure your paths are in the following structure:

"/subdirectories/file.fxml"

So if your fxml-files are located at: resources/layout/main.fxml:

"/layout/main.fxml"

So / is your resource directory

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