Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » button.getImage() in RAP2.3 error(ImageDescriptor.createFromImage( buttonQ.getImage() ))
button.getImage() in RAP2.3 error [message #1408178] Thu, 14 August 2014 08:42 Go to next message
Eclipse UserFriend
This error occurs in RAP 2.3 only, no error at all in RAP 2.2 and earlier.

In order to reuse the gif images, I use a SysIcon.ICON_QUERY as below, after I closed the 1st session of webpage without disposing the gif image, the following sessions occur error at ImageDescriptor.createFromImage( buttonQ.getImage() ), but the buttonQ.getImage() is not null and not disposed!

------------------------
public class SysIcon {
public final static Image ICON_QUERY;

public SysIcon(){}

public static Image loadImage( Display display, String name ) {
Image result = null;
InputStream stream = SysIcon.class.getClassLoader().getResourceAsStream( name );
if( stream != null ) {
try {
result = new Image( display, stream );
} finally {
try {
stream.close();
} catch( IOException unexpected ) {
throw new RuntimeException( "Failed to close image input stream", unexpected );
}
}
}
return result;
}

public static Image loadImage( String name ) {
return loadImage(Display.getDefault(), name);
}

static{
ICON_QUERY = loadImage( "icon/Q.gif" );
}
}

Button buttonQ = new MyButton(compFuncBar...
buttonQ.setImage( SysIcon.ICON_QUERY )
.
.
// if closed the 1st opened page, the following statement occurs error
final ImageDescriptor myImage = ImageDescriptor.createFromImage( buttonQ.getImage() );

Action myAction = new Action( actionCaption, myImage ) {
.....
}
----------------------

java.lang.NullPointerException
at org.eclipse.swt.graphics.Image.getImageData(Image.java:347)
at org.eclipse.jface.resource.ImageDataImageDescriptor.<init>(ImageDataImageDescriptor.java:36)
at org.eclipse.jface.resource.ImageDescriptor.createFromImage(ImageDescriptor.java:104)
at tw.com.cimnet.hr.iduqp.FillFuncBar.iduqBar(FillFuncBar.java:142)
----------------------

Thank you!
Re: button.getImage() in RAP2.3 error [message #1408180 is a reply to message #1408178] Thu, 14 August 2014 08:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
you don't need such a code. All images in RAP (their image data) are
internally reused by the framework. As RAP is multiuser framework, you
must avoid static references (if you don't really want to share
information between the UI sessions).
Best,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: button.getImage() in RAP2.3 error [message #1408711 is a reply to message #1408180] Fri, 15 August 2014 17:41 Go to previous message
Eclipse UserFriend
Hi, Ivan,

Thank you!
According to your reply, I changed the code to be:
-------------------
public class SysIcon {
public final static String ICON_QUERY = "icon/Q.gif";

public SysIcon(){}

public static Image loadImage( Display display, String name ) {
Image result = null;
InputStream stream = SysIcon.class.getClassLoader().getResourceAsStream( name );
if( stream != null ) {
try {
result = new Image( display, stream );
} finally {
try {
stream.close();
} catch( IOException unexpected ) {
throw new RuntimeException( "Failed to close image input stream", unexpected );
}
}
}
return result;
}

}

Button buttonQ = new MyButton(compFuncBar...
buttonQ.setImage( SysIcon.loadImage(buttonQ.getDisplay(), SysIcon.ICON_QUERY ));
.
.
// the following statement works well now
final ImageDescriptor myImage = ImageDescriptor.createFromImage( buttonQ.getImage() );
-------------------

As I know self-created font/color/image should be manually disposed at last, where and when to dispose the image on the buttonQ then?


Best Reagrds,
Previous Topic:Source code from the RAP demo plug-ins
Next Topic:Setting up target platform for RAP 2.3 and Teneo 2.0
Goto Forum:
  


Current Time: Wed Jul 23 21:24:46 EDT 2025

Powered by FUDForum. Page generated in 0.08212 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top