Eclipse 导出的 Runnable JAR 未显示图像 [英] Eclipse exported Runnable JAR not showing images

查看:26
本文介绍了Eclipse 导出的 Runnable JAR 未显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行从 Eclipse 导出的 JAR 文件时,我的图像不会加载.

My images will not load when running a JAR file exported from Eclipse.

我在资源类包中有图像.我也尝试过图像源文件夹,但没有成功.

I have the images in a resources class package. I've tried a images source folder as well with no luck.

从 Eclipse 加载时完美运行.图像位于导出的 JAR 文件中,因此可以正常导出.

Works perfectly when loaded from Eclipse. The images are in the exported JAR file, so they're exporting fine.

我试过了:

label.setIcon(new ImageIcon(MainFrame.class.getResource("/resources/header.jpg")));

我也试过:

URL url = getClass().getResource("/resources/header.jpg");
Image image = Toolkit.getDefaultToolkit().getImage(url);
label.setIcon(new ImageIcon(image));

还有:

try
{
    label.setIcon(new  ImageIcon(ImageIO.read(getClass().getResource("/resources/header.jpg"))));
}
catch (IOException e1)
{
    e1.printStackTrace();
}

有什么建议吗?

推荐答案

问题是我的 Windows 配置文件中有这个项目......它有一个!"在其中...(DeNitE!-> 是我的 Windows 配置文件的名称)

The problem was I had this project in my Windows profile... that had an "!" in it... (DeNitE! -> was the name of my Windows profile)

一旦我将其更改为 DeNitE(没有 !),它就可以正常工作......

As soon as I changed it to DeNitE (without the !) it worked fine...

这篇关于Eclipse 导出的 Runnable JAR 未显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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