I have found a solution!
it seems that in gamePanel, after I declared my BufferedImage, I forgot to add-
Graphics g = image.getGraphics();
sorry guys, I feel so stupid XD
Question
I am making a game and I am stuck trying to get the image to screen. I states that-
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
I am sure that my image path is the right path, but it keeps stating that it's not.
background = new Background("C:/hello/flappybird.png");
The "debug" section of my workspace states that there is a problem with
background.render(g);
specifically, with
g.drawImage(img,(int)x,(int)y,null);
and I have no idea why it is doing this. I am 100% sure my build path is right!
EDIT: just incase you want to know the constructor of the background class:
public Background(String s) {
try {
img = ImageIO.read(this.getClass().getResource(s));
} catch (IOException e) {
e.printStackTrace();
}
}
Solution 2
I have found a solution!
it seems that in gamePanel, after I declared my BufferedImage, I forgot to add-
Graphics g = image.getGraphics();
sorry guys, I feel so stupid XD
OTHER TIPS
This error indicates the image file wasn't found. To be sure that this is really the case, I urge you to execute ImageIO.read()
directly and check the result:
BufferedImage icon = ImageIO.read("C:/hello/flappybird.png");
Also, it's not a good practice to use resources outside the classpath. I strongly suggest you to change your class Background
to use classpath resources. Somewhere inside your Background
class, you could add:
public class Background {
public Background(String filename) {
// Some code here
BufferedImage image = ImageIO.read(getClass().getResource("/resources/images/" + filename));
// More code here
}
}