'Exception in thread "main" java.lang.IllegalArgumentException: input == null

A lot of people have already asked this question, but I can't just solve it. I'm trying to do a 2d Game following this tutorial, now I'm in the sprite character section, and I'm adding images to my GamePanel.

Here's the StackTrace:

Exception in thread "main" java.lang.IllegalArgumentException: input == null!
    at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1356)
    at entity.Player.getPlayerImage(Player.java:53)
    at entity.Player.<init>(Player.java:25)
    at main.GamePanel.<init>(GamePanel.java:29)
    at main.Main.main(Main.java:17)

This is the critical Method:

public void getPlayerImage() {
        try {
            up1 = ImageIO.read(getClass().getResourceAsStream("/res/player/boy_up_1.png"));
            up2 = ImageIO.read(getClass().getResourceAsStream("/res/player/boy_up_2.png"));
            down1 = ImageIO.read(getClass().getResourceAsStream("/res/player/boy_down_1.png"));
            down2 = ImageIO.read(getClass().getResourceAsStream("/res/player/boy_down_2.png"));
            left1 = ImageIO.read(getClass().getResourceAsStream("/res/player/boy_left_1.png"));
            left2 = ImageIO.read(getClass().getResourceAsStream("/res/player/boy_left_2.png"));
            right1 = ImageIO.read(getClass().getResourceAsStream("/res/player/boy_right_1.png"));
            right2 = ImageIO.read(getClass().getResourceAsStream("/res/player/boy_right_2.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


Solution 1:[1]

In getPlayerImage() you probably use the wrong path for your images. This results in getClass().getResourceAsStream being null. This then results in giving the read()-method null as instead of a File.

Snippet rom ImageIO:

/** @exception IllegalArgumentException if {@code input} is
 * {@code null}.
 * @exception IOException if an error occurs during reading or when not
 * able to create required ImageInputStream.
 */
public static BufferedImage read(File input) throws IOException {
    if (input == null) {
        throw new IllegalArgumentException("input == null!");
    }
    //...    
}

Solution 2:[2]

Do you have set the res folder as your resources folder in your IDE?

If it is the projects resource folder you can try to recreate the project. I had a similar problem and recreating the Project worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 lm41