I have this code:
val url: URL = getClass.getResource("com/mysite/main/test.fxml")
and it always returns null (or Unit). I have only two files in the project:
MyProj/src/com/mysite/main/Test.scala
MyProj/src/com/mysite/main/test.fxml
and when I run the Test.scala the url value is always null.
I just tried rebuild the project, I am using IntelliJ IDEA. What am I doing wrong here?
You have three options:
take advantage of relative path to your current package (where
Test.classis):you can use absolute path:
or load through the
ClassLoader(note that it always start from root):In IntelliJ IDEA, make sure you have added
;?*.fxmlto the:Settings(Preferenceson Mac) |Compiler| Resource Patterns.