• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading an image from another package  RSS feed

 
Mikpo Siru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a package which contains an image that I want to use in another package.


To use graphic.png in another package, I have tried:



However the image doesn't appear. Any help is appreciated.

Thanks.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that class ClassB is inside package package_a:
Relative resource paths work similar to relative file paths; you can use .. to go up one level.


By the way, you should never ever catch exceptions and ignore them like that. If an exception occurs you won't know what went wrong.
 
Mikpo Siru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. ClassB is in another package, outside of Package A. I did previously have all images in the same package, but then I created a generic library package and tranferred the images to there.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The technique is still valid. Use .. to go up one level until you're at the root, then use images/graphic.png. Alternatively you can use /images/graphic.png as that's an absolute path, and will start at the class path root. In this case it should find the image.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!