button.getImage() in RAP2.3 error [message #1408178] |
Thu, 14 August 2014 12:42 |
David Lee Messages: 81 Registered: May 2013 |
Member |
|
|
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 #1408711 is a reply to message #1408180] |
Fri, 15 August 2014 21:41 |
David Lee Messages: 81 Registered: May 2013 |
Member |
|
|
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,
|
|
|
Powered by
FUDForum. Page generated in 0.04127 seconds