Please help me

Here's the code in question:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public BufferedImage loadImage(String name) { URL url = getClass().getClassLoader().getResource(name); try { return ImageIO.read(url); } catch (Exception e) { System.out.println("Cannot load image " + name +" from "+url); System.out.println("The error was : "+e.getClass().getName()+" "+e.getMessage()); System.exit(0); return null; } } public void draw(Graphics2D g) { BufferedImage bi = loadImage("hero.bmp"); g.drawImage(bi,x,y,null); } |
When I run it... the getClass().getClassLoader().getResource(name); method returns null, eventhogh hero.bmp is in the same folder. How do I fix that?
EDIT: Nevermind, I fixed it by changing
to
1
| loadImage("<packagename>/hero.bmp"); |