Garmaine Staff asked 2 years ago

Iam coding game as part of my homework and I'm trying to load a image from res folder but I'm getting NullPointerException: Exception in thread "Thread-0" java.lang.IllegalArgumentException: input == null! at java.desktop/ at prg_hra/esrever.BufferedImageLoader.loadImage( at prg_hra/esrever.Hra.init( at prg_hra/ at java.base/

The res folder is already in Java Build Path and I'm 99% sure that I'm putting in the right path. I got BufferedImageLoader Class:

public class BufferedImageLoader {

private BufferedImage image;

public BufferedImage loadImage(String path) {

    try {
        image =;
    } catch (IOException e) {
    return image;

and I'm using it in inti metode in game class: private void init() {


    BufferedImageLoader loader = new BufferedImageLoader();
    level = loader.loadImage("/res/level.png");     

    handler = new Handler();

    kam=new Kamera(0,0);

    handler.addObjekt(new Hrac(100, 100, handler, ObjektID.Hrac));


    this.addKeyListener(new KeyInput(handler));

I've looked at some similar problems of other people, but they mostly just used wrong path..

EDIT: I also tried level = loader.loadImage("level.png"); and level = loader.loadImage("/level.png"); neither worked.