IntelliJ IDEA - getClass()。getResource(" ...")返回null [英] IntelliJ IDEA - getClass().getResource("...") return null

查看:87
本文介绍了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.

这篇关于IntelliJ IDEA - getClass()。getResource(" ...")返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆