【问题标题】:Afterburner.fx fail load resource from object injectedAfterburner.fx 无法从注入的对象加载资源
【发布时间】:2014-11-25 16:47:44
【问题描述】:

我在我的项目中使用 afterburner.fx DI。一切正常,除非我尝试将文件加载到从资源文件夹注入的对象中。

我尝试输入getClass().getResource()Class_name.class.getResource ...但似乎不起作用。

例如,我尝试加载图像以用作应用程序的图标,因此我尝试使用(其他不起作用的方法):

getIcons().add(new Image(Thread.currentThread().getContextClassLoader().getResourceAsStream("/img/logo.png")));

所有方式都返回相同的错误:

java.lang.NullPointerException: Input stream must not be null

【问题讨论】:

    标签: java dependency-injection nullpointerexception javafx embedded-resource


    【解决方案1】:

    最后我发现了和Afterburner.fx没有关系的问题:

    当我使用 maven 创建项目时,我没有在我的 POM 中包含来自文件夹 img 的资源,所以我总是遇到上述错误。也许,我可以加载其他默认资源,例如 css 样式。

    正确配置我的 POM 后,一切正常。

    【讨论】:

      猜你喜欢
      • 2012-07-26
      • 2013-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      相关资源
      最近更新 更多