Ho un problema con il caricamento di immagini
Qui c'è il codice
codice:
public static BufferedImage getSprite(String file,Object obj)
{
BufferedImage sprite = null;
try
{
sprite=ImageIO.read(obj.getClass().getResource(file));
}
catch(Exception e)
{
System.out.println("File doesn't exist");
}
return sprite;
}
Questo è il codice che da problemi
codice:
public class Grass
{
BufferedImage grass=SpriteHandler.getSprite("/Resources/grass_tile.gif",this);
public void render(Graphics g)
{
g.drawImage(grass, 0, 0, null);
}
}
Poi tutto questo l'ho aggiunto alla classe "principale" con Grass grass=new Grass();
Quando avvio il programma dice
codice:
Exception in thread "Thread-2" java.lang.NullPointerException
at Game.render(Game.java:99)
at Game.run(Game.java:75)
at java.lang.Thread.run(Unknown Source)
Qualcuno può spiegarmi perchè?, Anche perchè utilizzando lo stesso metodo getSprite in altre classi non da problemi
Grazie in anticipo