Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with getResource Method

807607Jan 4 2007 — edited Jan 4 2007
Hello frds,

i m using follwg code to load images in my swing comp..
This code is working properly when i m trying to run my application using simple run command.
I added one print statement to check the getResource method.
that is working fine when run my application using run command.
But when i m trying to launch my application using jar file.
getResource method is not working & returning URL is null.
I m using getProperties to load images.
Please try to solve this prob.

Protected Static ImageIcon createImageIcon(String path)
{
ClassLoader cl = MP3Display.class.getClassLoader();
URL imgURL = cl.getResource(path);

System.out.println("SURBHI : Test URL" + imgURL + " ---" +path);

if(imgURL !=null)
{
return new ImageIcon(imgURL);
}
else
{
System.err.println("Could't find file "+path);
return null;
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2007
Added on Jan 4 2007
3 comments
171 views