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

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

问题描述

查看了关于 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 加载图像:始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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