Cannot get resource

1. Getting resource

public static ImageIcon createImageIcon(String path) {

java.net.URL imgURL = GUImain.class.getResource(path);

if (imgURL != null) return new ImageIcon(imgURL)

else return null;

}

Call from application's constructor:

public GUImain(JFrame frame) {

...

ImageIcon objectIcon = createImageIcon("Img/objico.gif");

...

}

createImageIcon always return null independent from path i pass to it.

objico.gif presents in <path to application>/Img/objico.gif

2. How to get context path of the application?

[612 byte] By [BrotherFlamea] at [2007-11-27 10:03:48]
# 1
According to the example here: http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html, your syntax is correct.make sure you have the Img directory under your application project.refresh your application and make a clean/rebuild.
java_2006a at 2007-7-13 0:38:47 > top of Java-index,Java Essentials,Java Programming...
# 2
Make sure that your executable jar have Img/objico.gif and also make sure resorces are being access with exact name(case sensitive).
JL.Nayaka at 2007-7-13 0:38:47 > top of Java-index,Java Essentials,Java Programming...
# 3
Mistic.I have folder "Img" inside my "GUI" package and file objico.gif inside folder.Call ImageIcon objectIcon = createImageIcon("Img/objico.gif"); takes no effect. I have default icons.
BrotherFlamea at 2007-7-13 0:38:47 > top of Java-index,Java Essentials,Java Programming...