Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Yet another image loading problem thread  (Read 583 times)
0 Members and 1 Guest are viewing this topic.
Offline DanoruX

JGO n00b
*

Posts: 19


Java games rock!


« on: 2005-01-14 11:47:13 »

Please help me Grin

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

1  
loadImage("hero.bmp");


to

1  
loadImage("<packagename>/hero.bmp");
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.081 seconds with 20 queries.