This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: problem embedding resources
you need to replace
.getResourceAsStream("swt.gif")));
with
.getResourceAsStream("/swt.gif")));
Generally you should have package prefix for resources (they are in
the context of a class), and as a side note, your example fails under
sun jvm.
Other tip is to compile resources with package prefix also, for
example if the gif was on the ex.resource package:
gcj -c -o swt.o --resource=ex/resource/swt.gif ex/resource/swt.gif
and in java you have:
getResourceAsStream("resource/swt.gif")
On 10/20/05, Camilla Orlandi <corlandi@land.it> wrote:
> Andrew Haley ha scritto:
>
> >If you give us an example we can reproduce, with the commands and the
> >files you use, we could help yopu.
> >
> >OK, you don't have to attach the GIF; we can make one ourselves. But
> >you do have to attach all the source code and all the commands.
> >
> >Andrew.
> >
> >
> ok, sorry, here is the HelloWorld.java code:
>
>
> *********************************
>
> package ex;
>
> import org.eclipse.swt.widgets.*;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.*;
>
> public class HelloWorld {
>
> public HelloWorld(){
>
> Display d=new Display();
> Shell s=new Shell(d);
> s.setSize(100,200);
>
> Label aLabel=new Label(s, SWT.BORDER);
> aLabel.setBounds(0,0,100,100);
> aLabel.setImage(
> new Image(d,
> HelloWorld.class
> .getResourceAsStream("swt.gif")));
>
> s.open();
>
> while(!s.isDisposed()){
> if(!d.readAndDispatch()){
> d.sleep();
> }
> }
>
> d.dispose();
> }
>
> public static void main(String[] args){
> HelloWorld hw=new HelloWorld();
> }
>
> }
>
> *********************************
>
> commands:
>
> gcj -c -o swigtif.o --resource=swt.gif swt.gif
>
> gcj -s -fjni --main=ex.HelloWorld -s -o HelloWorld.exe
> ex/HelloWorld.java swtgif.o
>
>
>
> using the same code, not includeing it in the ex package, it's ok.
> thanks
>
> Camilla
>
>
>