aspose file tools*
The moose likes I/O and Streams and the fly likes Problem loading images in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem loading images in Eclipse" Watch "Problem loading images in Eclipse" New topic
Author

Problem loading images in Eclipse

Jack Okerman
Greenhorn

Joined: Oct 06, 2011
Posts: 3
I'm running into some problems importing images in Eclipse. I'm trying to load some images and then store them in a Vector. Here is my code:
The program compiles, but when I run it, I get a NullPointerException when I try to access the BufferedImage stored in the vector. I have all the images stored in the src folder for the project in Eclipse. I tried running the program using on my school's UNIX server and there were no issues. Any help would be greatly appreciated. I can post the rest of my code if that would help.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Don't use File to load the images, use Class.getResource(AsStream).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jack Okerman
Greenhorn

Joined: Oct 06, 2011
Posts: 3
I tried using the Class.getReasourceAsStream() method and I still get the NullPointerException. Here is my updated code:
Jack Okerman
Greenhorn

Joined: Oct 06, 2011
Posts: 3
Whoops. I accidentally marked the topic as resolved. THE TOPIC IS NOT RESOLVED. I can't figure out how to undo.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

First you said the image was in a file in the current working directory. But that wasn't right because Eclipse's current working directory is unrelated to any of your projects. So now you've changed it to say the image is in the same folder as the class that code is in. Apparently that isn't the case either. Have you read the API documentation for the getResourceAsStream method to see if it says anything about that?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem loading images in Eclipse