• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem loading images

 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's a pic of the directory structure

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

Dave
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And are the resources and images also located in the folder with the class files?
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic