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

查看:184
本文介绍了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));

And:

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天全站免登陆