Please help me ;D
Here’s the code in question:
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
loadImage("hero.bmp");
to
loadImage("<packagename>/hero.bmp");