I am trying to write an imageloading function for my program, however it is doing something strange.
public void loadImage(BufferedImage img, String filepath) {
try {
img = ImageIO.read(new File(filepath));
}
catch (IOException e) {
}
}
And I am calling it like so:
BufferedImage background = null;
loadImage(background, path);
I see in debugging that img
loads properly, but background
remains null the whole time and causes a NullPointerException
.
When I change to a direct reference to background like background = ImageIO.read(new File(filepath));
then it works just fine.
What's even more strange is that System.out.println(img == background)
prints true
.
What am I doing wrong?