• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem loading images in Eclipse

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use File to load the images, use Class.getResource(AsStream).
 
Jack Okerman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried using the Class.getReasourceAsStream() method and I still get the NullPointerException. Here is my updated code:
 
Jack Okerman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoops. I accidentally marked the topic as resolved. THE TOPIC IS NOT RESOLVED. I can't figure out how to undo.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic