简体   繁体   English

ImageIO.read()返回null

[英]ImageIO.read() returns null

I have a problem regarding the ImageIO.read() function: 我对ImageIO.read()函数有问题:

URL imageURL = this.getClass().getResource(sheetPath);
spriteSheet = ImageIO.read(imageURL); 

The ImageIO function returns null even though the URL is correct (it leads to a .png file). 即使URL正确,ImageIO函数也将返回null(导致生成.png文件)。 I've tried to put the getResource() as a parameter for the read function, but that didn't work either. 我试图将getResource()用作读取函数的参数,但这也不起作用。 Has anyone encountered a similar problem and maybe found a solution? 有没有人遇到过类似的问题,也许找到了解决方案?

Regards 问候

Edit: 编辑:

sheetPath is "/images/pizzaGirl.png" sheetPath是“ /images/pizzaGirl.png”

imageURL is "file:/Users/Kevin/Dropbox/workspace/PizzaGirl/bin/images/pizzaGirl.png" imageURL是“文件:/Users/Kevin/Dropbox/workspace/PizzaGirl/bin/images/pizzaGirl.png”

images is in the "res" folder which I added to the classpath via the eclipse's run configurations 图像在“ res”文件夹中,该文件夹是通过eclipse的运行配置添加到类路径中的

Okay I tried to replace my path with a different image and it worked. 好的,我尝试用另一张图片替换我的路径,并且可以正常工作。 I went back into photoshop, exported my image again and voilà, it works. 我回到了photoshop,再次导出了我的图片,然后开始工作了。

Check if the path is really correct. 检查路径是否正确。 To do this write: 为此,请写:

System.out.println(new File(yourPathHere).exists());

then if it returns false please post the path. 然后如果返回false,请发布路径。 I will check if it is correct. 我会检查是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM