why can't Image be found by using "new Image(path)" in rcp? [message #467140] |
Sun, 29 April 2007 01:20 |
Eclipse User |
|
|
|
Originally posted by: wangyang227.21cn.com
why can't Image be found by using "new Image(path)" in rcp?
It can be found when running as a single swt class.
e.g there is a picture in workspace/rcp_project/icons/ff.gif
I use new Image("icons/ff.gif") to load it, it can be found when runned as a single swtclass,but cannot be found when runned
as a RCP
who can help me? thanks
|
|
|
|
|
Re: why can't Image be found by using "new Image(path)" in rcp? [message #467153 is a reply to message #467151] |
Sun, 29 April 2007 18:07 |
Alex Blewitt Messages: 946 Registered: July 2009 |
Senior Member |
|
|
Does putting / on the front of the string help?
You could also try using new Image(getClass().getResourceAsStream("/icons"), but then your icons/ would have to be on the classpath (e.g. copied into a bin/ location).
The problem is that the location of the file can't be guaranteed when loaded as a File name, so what you have to do is load the bytes via either getClass().getResourceAsStream(), or use bundle.getEntry() to load the resource from the bundle itself. Both have their problems ... the former is easier to code, but you need to make sure they're on the classpath (and in dev mode in Eclipse, that's not usually the case), whilst the latter will just search the Bundle, but you have to acquire the bundle context in order to get the bundle itself, which is sometimes more tricky.
Unfortunately, manipulating resources in Eclipse is unnecessarily difficult owing to how PDE treats the build resources. If instead of having the notion of classes living in one place and resources mounted at the root, then you wouldn't have all this difficulty; but that's not likely to change any time soon.
Alex.
|
|
|
Powered by
FUDForum. Page generated in 0.02954 seconds