Scala getClass.getResource() returning null

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?

Answers


You have three options:

  • take advantage of relative path to your current package (where Test.class is):

    getClass.getResource("test.fxml")
    
  • you can use absolute path:

    getClass.getResource("/com/mysite/main/test.fxml")
    
  • or load through the ClassLoader (note that it always start from root):

    getClass.getClassLoader.getResource("com/mysite/main/test.fxml")
    

In IntelliJ IDEA, make sure you have added ;?*.fxml to the:

Settings (Preferences on Mac) | Compiler | Resource Patterns.


Need Your Help

Can final parameters be qualified in some way to resolve naming conflicts with anonymous class members?

java scope anonymous-class

"Why are you doing this what is wrong with you?" notwithstanding, is there any way to accomplish this without changing the final method parameter name?

Top bar visible in iPhone5 but not in iPhone6

ios xcode

I am running my code on simulator iPhone5 and iPhone6. The problem is top bar is visible in iPhone5 but not in iPhone6 or iPhone6+. Please see attahced images.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.