Strange issue with getResourceAsStream()

Erik Poupaert erik.poupaert@skynet.be
Wed Jul 2 12:52:00 GMT 2003


Hi Steve,
I regularly use getResourceAsStream() by myself, and I don't have any
problems with it. There are potentially two reasons why you're having this
problem. 
One. You're linking statically, and the SWT library sources have not been patched to
force reflection to work. For both SWT for windows as for GTK2, the patch should
be in the file FileFormat.java in the namespace org.eclipse.swt.internal.image. On
Windows, the default is static linking.
Two. There is something wrong with the core protocol key you're using. 
If you're compiling com/mycompany/myapp/mypicture.gif for access with
getResourceAsStream() you should use a core protocol key similar to:
gcj --resource com/mycompany/myapp/mypicture.gif \
 -o wherever/mypicture.gif.o \
 -c com/mycompany/myapp/mypicture.gif
You shouldn't make errors in the core protocol key if you want getResourceAsStream()
to work properly:
 --resource com/mycompany/myapp/mypicture.gif
Below yo will find the patch that must be present; or a similar fix that forces
reflection to work in the SWT image-related sources, even in case of static linking:
public abstract class FileFormat {
	static final String FORMAT_PACKAGE = "org.eclipse.swt.internal.image"; //$NON-NLS-1$
	static final String FORMAT_SUFFIX = "FileFormat"; //$NON-NLS-1$
	static final String[] FORMATS = {"WinBMP", "WinBMP", "GIF", "WinICO", "JPEG",
"PNG"}; 
//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$
//$NON-NLS-6$
//X ----> make sure they're included when statically linking
	private static final Class WINBMP_FILEFORMAT = WinBMPFileFormat.class;
	private static final Class GIF_FILEFORMAT = GIFFileFormat.class;
	private static final Class WINICO_FILEFORMAT = WinICOFileFormat.class;
	private static final Class JPEG_FILEFORMAT = JPEGFileFormat.class;
	private static final Class PNG_FILEFORMAT = PNGFileFormat.class;
//X <----	
	LEDataInputStream inputStream;
	LEDataOutputStream outputStream;
...


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /