I’m looking to display an image, but the return line seems to return null, which is weird because i’m pretty sure my path is correct.
I’m using NetBeans and java swing lib.
protected static BufferedImage loadImage(String path) {
try {
return ImageIO.read(Creation.class.getClassLoader().getResource("resources/animals/squirrel.png"));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
here is my architecture
i tried changing the path to resources.animals/squirrel.png, but of course this didn’t changed anything.
New contributor
Leandro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.