从Jar加载图像:始终为null [英] Load Image from Jar: Always null

查看:109
本文介绍了从Jar加载图像:始终为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看SO上的其他帖子并且他们没有解决此问题。

Looked at other posts on SO and they did not solve this issue.

我正在尝试从我的jar文件加载图像。它一直是空的。该图片位于:

I'm trying to load an image from my jar file. It is continuously coming up as null. The image is located under:

.Jar file > images > BLOCK.png

加载我正在做的图像:

BufferedImage bImg;
URL url = getClass().getResource("/images/BLOCK.png");
try {
    bImg = ImageIO.read(url);
} catch (IOException ex) {
    Logger.getLogger(TileEngine.class.getName()).log(Level.SEVERE, null, ex);
}

url与bImg一样无效。

url is null as is bImg.

不要担心区分大小写,因为我已经检查过了。

Do not worry about case sensitivity as I've already checked that.

推荐答案

试试这个:

Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/BLOCK.png"));

这篇关于从Jar加载图像:始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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