【问题标题】:Combining Jar File with images in IntelliJ将 Jar 文件与 IntelliJ 中的图像结合起来
【发布时间】:2016-09-01 19:21:35
【问题描述】:

我在网站上研究了这个主题,并尝试了解决方案,但到目前为止对我没有任何帮助。我在 IntelliJ 中创建了一个可以很好编译的简单程序,但是当我将其导出并放入 JAR 时,由于图像而出现错误。当我拿走图像时,我能够正确构建和加载 JAR 文件。我将图像保存在名为 sample 的子文件夹中的 SRC 文件中。

public class Main extends Application {

    Image image = new Image(String.valueOf(getClass().getResource("/buttona.png")));

    Button button1 = new Button("", new ImageView(image));
    Button button2 = new Button();

【问题讨论】:

标签: intellij-idea jar javafx-8 src


【解决方案1】:

我想通了,想为未来的用户发布解决方案。当我使用底部显示的格式时,它起作用了。关键是放置 GetClassLoader,然后找到一条可行的路径。

np0_up.png 是文件

Image Num0 = new Image(getClass().getClassLoader().getResourceAsStream("sample/np0_up.png"));

【讨论】:

  • 还要确保文件名是否有大写的 PNG 以便在您的 ide 中放置 PNG 而不是 png
猜你喜欢
  • 1970-01-01
  • 2014-08-07
  • 1970-01-01
  • 1970-01-01
  • 2015-04-11
  • 2011-01-02
  • 1970-01-01
  • 2020-11-08
  • 2017-08-12
相关资源
最近更新 更多