File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with MyClass.class.getResource()

 
Mario A. Villamizar
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "/").
 
Mario A. Villamizar
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic