load an image from within a plugin [message #514084] |
Fri, 12 February 2010 06:41  |
Eclipse User |
|
|
|
Hi all,
I've got a plugin with an "img" directory listed in the classpath and from which I'd like to load an image (the application startup logo shown in a view) with the following code:
static {
try {
// load a dummy image and read each byte, then set the bytes as
// those for the
// dummy image
File dummyImage = new File(DEFAULT_LOGO_IMAGE_FILE_NAME);
// load the image thru the bundle facilities
if( ! dummyImage.isAbsolute() || ! dummyImage.exists() || ! dummyImage.isFile() ){
Bundle bundle = Platform.getBundle( Activator.PLUGIN_ID );
IPath imagePath = new Path( DEFAULT_LOGO_IMAGE_FILE_NAME );
URL fileURL = FileLocator.find(bundle, imagePath, Collections.EMPTY_MAP);
fileURL = FileLocator.toFileURL(fileURL);
dummyImage = new File( fileURL.getPath() );
}
InputStream is = new FileInputStream(dummyImage);
dummyImageBytes = new byte[is.available()];
is.read(dummyImageBytes);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
The above code loads the bytes of the image (for further elaboration), however the problem is that the FileLocator throws a NullPointerException since the fileURL is always null. The searched image (DEFAULT_LOGO_IMAGE_FILE) has been set either to img/logo.png or /img/log.png. In either case the null pointer exception arises:
java.lang.NullPointerException
at org.eclipse.core.internal.runtime.Activator.getURLConverter(Activator.java:313)
at org.eclipse.core.runtime.FileLocator.toFileURL(FileLocator.java:205)
at hrpm.rcp.gui.view.BaseImageView.<clinit>(BaseImageView.java:322)
... 67 more
The line 322 is the following:
fileURL = FileLocator.toFileURL(fileURL);
The plugin.xml should not even contain the "img" directory as runtime classpath entry, since it is at the root of the plugin directory, right? So does anybody knows how can I solve the problem? (I've also tried to load the image thru a classloader as resource but without any success).
|
|
|
|
|
|
|
|
|
Re: load an image from within a plugin [message #518247 is a reply to message #514447] |
Wed, 03 March 2010 10:21   |
Eclipse User |
|
|
|
I've checked and the img path is contained into the bundle classpath, should it be also somewhere else?
Bundle-ClassPath: classes/,
org.springframework.beans-3.0.0.M4.jar,
org.springframework.core-3.0.0.M4.jar,
org.springframework.jdbc-3.0.0.M4.jar,
org.springframework.transaction-3.0.0.M4.jar,
commons-logging-1.1.1.jar,
conf/,
postgresql-8.3-603.jdbc4.jar,
img/,
org.springframework.aop-3.0.1.RELEASE-A.jar,
aopalliance.jar
Moreover, if I load an image thru the ImageDescriptor how can I get the image bytes from it?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06827 seconds