GeeCON Prague 2014*
The moose likes Java in General and the fly likes problem loading images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "problem loading images" Watch "problem loading images" New topic
Author

problem loading images

Dave Robbins
Ranch Hand

Joined: Sep 16, 2003
Posts: 131
I'm fooling around with jogl and I'm having trouble loading images to use as textures
my application is in a package named toys
the main app contains a JTabPane which has several tabs that do different stuff
each tab contains a JPanel, the individual panels are in a package called (surprise) panels
the image I want to load is in a package called (surprise) images
so it looks something like this



so, in my IDE (netbeans) I can load the image with this code



this says I have to go up a directory from where the panel is, then go into the images dir, it works fine in netbeans
it doesn't work once it's made into a jar file and I try to run it from the command line
any good pointers to trying to understand the whole path deal when it comes to stuff like this?
I'm kinda confused at the moment

TIA
Dave
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
perhaps the slashes need to be back-slashes

//getClass().getResource("../images/normal_earth_2400.jpg")
getClass().getResource("..\\images\\normal_earth_2400.jpg")
Dave Robbins
Ranch Hand

Joined: Sep 16, 2003
Posts: 131
nope
changing to backslashes it still works in the IDE but not from the command line
continuing to investigate, ideas welcome

Dave
Dave Robbins
Ranch Hand

Joined: Sep 16, 2003
Posts: 131
hmm, that's annoying
if I change my code to this



and dump the jpg into the directory with my panels it works both in the IDE and from the command line
apparently some sort of path issue
unfortunately, I want my images in their own folder

Dave
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Can you show us the exact directory structure of the project? Something tells me that the IDE is not using a bin folder or something similar, and the command line JVM is, or vice versa.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dave Robbins
Ranch Hand

Joined: Sep 16, 2003
Posts: 131
here's a pic of the directory structure

http://www.drobbins.net/pics/toys.jpg

Dave
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

And are the resources and images also located in the folder with the class files?
Dave Robbins
Ranch Hand

Joined: Sep 16, 2003
Posts: 131
the file I'm trying to open is normal_earth_2400.jpg
in the picture you can see I have it in the directory with my various panels
the code I use to open it is



that works properly both in the IDE and running the jar file from the command line
what I'd like to do is have that jpg in the images directory, I don't want graphics file mixed with my source code, I've been down that road, trust me, "madness lurks there" :roll:

interestingly, I just made an images directory under the resources dir which is under panels
I place the jpg there and I can open it with



I can live with that but I don't understand why the first way didn't work
it doesn't seem to want to let me use .. to go up a directory
Ideas welcome but I can live with what I have

Dave
 
GeeCON Prague 2014
 
subject: problem loading images