IllegalArgumentException 输入 == null [英] IllegalArgumentException Input == null

查看:59
本文介绍了IllegalArgumentException 输入 == null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像读取为 InputStream.但出于某种原因,我总是收到 IllegalArugmentException.

I am trying to read an Image as an InputStream. But for some reason I always get an IllegalArugmentException.

这是我的代码:

BufferedImage i = null; 
i = ImageIO.read(getClass().getResourceAsStream("/res/graphics" + path));

推荐答案

原因:

您的资源评估为 null,这就是异常

Your resource evaluates to null and that is why the exception

API 文档

抛出:IllegalArgumentException - 如果输入为 null.

Throws: IllegalArgumentException - if input is null.

解决方案:

如果 res/graphics/whatever 在根的类路径中,那么它将返回非空

If res/graphics/whatever is in classpath at root then it will return not null

这篇关于IllegalArgumentException 输入 == null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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