getResource has nothing to do with the class location, it is relative to the classpath.
You need to turn your class package into a directory path eg java.lang.String becomes /java/lang/ and then add your file /java/lang/bug1.png
Nick Petas wrote:I have this line in my code but it returns null although the file exists in the same folder as the java class :
Any ideas?
David is partly wrong. If the file is in the same location as the class file (so LabelFrame.class, not LabelFrame.java) then it is on the class path and it should be loaded properly. I think in your case you've put the image in the same folder with the source file, not the class file.
Thank you guys for your help.I used System.getProperty("java.class.path") temprorary to see what is the classpath and then I moved the png file from the src directory to the bin directory that I've go from the getProperty command.
Thank you for your help.
Description Resource Path Location Type
The serializable class LabelFrame does not declare a static final serialVersionUID field of type long LabelFrame.java /SimpleGui2/src/myPackage line 12 Java Problem
Rob Prime wrote:David is partly wrong. If the file is in the same location as the class file (so LabelFrame.class, not LabelFrame.java) then it is on the class path and it should be loaded properly. I think in your case you've put the image in the same folder with the source file, not the class file.
Nick Petas wrote:The only remaining warning from eclipse is that :
Description Resource Path Location Type
The serializable class LabelFrame does not declare a static final serialVersionUID field of type long LabelFrame.java /SimpleGui2/src/myPackage line 12 Java Problem
Any ideas guys of what it is?
Yes, it's a warning that your serializable class isn't declaring a serialVersionUID field.