IntelliJ IDEA - getClass()。getResource(" ...")返回null
我正在使用IntelliJ IDEA 13.1.5,我曾经使用Eclipse。我正在研究JavaFX应用程序,我尝试使用getClass()。getResource()在我的MainApp类中加载FXML文件。
我阅读了文档并尝试了几个想法,最后我有 null 。
I'm using IntelliJ IDEA 13.1.5, I used to work with Eclipse. I'm working on JavaFX application, I try to load FXML file within my MainApp class using getClass().getResource(). I read the documentation and I try several idea, at the end I have null.
这是层次结构:
dz.bilaldjago.homekode.MainApp.java
dz.bilaldjago.homekode.MainApp.java
dz.bilaldjago.homekode。 view.RootLayout.FXML
dz.bilaldjago.homekode.view.RootLayout.FXML
这是我使用的代码段:
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("view/RootLayout.fxml"));
我尝试了其他解决方案,例如从根提供网址并使用classLoader
I tried other solution such giving the url from the root and using the classLoader
结果是一样的。任何想法请
the result is the same. Any idea please
对于那些使用Intellij Idea的人:检查设置 - >编译器 - >资源模式
。
For those who use Intellij Idea: check for Settings -> Compiler -> Resource patterns
.
该设置包含应解释为资源的所有扩展。如果扩展不符合此处的任何模式,则class.getResource将使用此扩展名为资源返回null。
The setting contains all extensions that should be interpreted as resources. If an extension does not comply to any pattern here, class.getResource will return null for resources using this extension.