aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problem with MyClass.class.getResource() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem with MyClass.class.getResource() " Watch "problem with MyClass.class.getResource() " New topic
Author

problem with MyClass.class.getResource()

Mario A. Villamizar
Ranch Hand

Joined: Mar 14, 2002
Posts: 35
Hi,
I have the following code:

And I always get this output:
Couldn't find file: images/new.gif
yessss
So the file exists, and I'm giving the right path, what could be the problem
Thanks,


MA Villamizar
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

If the path given to getResource() is a relative path, as it is here, it's taken relative to the location of the .class file. Unless JTEdi.class is in the same directory that holds the images directory, this won't work. I believe it may work if you use an absolute path (one starting with "/").


[Jess in Action][AskingGoodQuestions]
Mario A. Villamizar
Ranch Hand

Joined: Mar 14, 2002
Posts: 35
hi,
I tryed with an absolute path and it does not work neather;I tryed this:
in side the method private static createImageIcon(string path)

I'm using packages and the class ActionCommand is in the editor.action package and the class that has the main method is in the package editor. The hole project is in a directory called sourceCode and the images are inside a directory called images inside the sourceCode directory, so I don't know if that matters.
Thanks,
Mario A. Villamizar
Ranch Hand

Joined: Mar 14, 2002
Posts: 35
Originally posted by Ernest Friedman-Hill:
If the path given to getResource() is a relative path, as it is here, it's taken relative to the location of the .class file. Unless JTEdi.class is in the same directory that holds the images directory, this won't work. I believe it may work if you use an absolute path (one starting with "/").

hi,
I tryed with an absolute path and it does not work neather;I tryed this:
in side the method private static createImageIcon(string path)
code:

File file = new File(path);
path = file.getAbsolutePath();
URL url = ActionCommand.class.getresource(path);
I'm using packages and the class ActionCommand is in the editor.action package and the class that has the main method is in the package editor. The hole project is in a directory called sourceCode and the images are inside a directory called images inside the sourceCode directory, so I don't know if that matters.
Thanks,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with MyClass.class.getResource()
 
Similar Threads
loading image
Escape sequences
Loading an Image
images in jar file
Loading from a resource folder returns null