*
The moose likes Beginning Java and the fly likes getClass().getClassLoader().getResource(path) always return null, even when the path is correct Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getClass().getClassLoader().getResource(path) always return null, even when the path is correct" Watch "getClass().getClassLoader().getResource(path) always return null, even when the path is correct" New topic
Author

getClass().getClassLoader().getResource(path) always return null, even when the path is correct

Daniel Gallant
Greenhorn

Joined: Sep 09, 2009
Posts: 27
I'm having an issue with the following code. the getClass().getClassLoader().getResource(path) always throws an exception, but the path used (and printed in the error message) are correct.



Thanks for all your help!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi Daniel,

"Correct" can be a relative term! The path should be relative to a location on the classpath; i.e., it's a path from the root of a jar file, or a path from the directory on the classpath. An absolute path from the root of your disk (for instance) will not work.


[Jess in Action][AskingGoodQuestions]
Daniel Gallant
Greenhorn

Joined: Sep 09, 2009
Posts: 27
D'Oh!!

I knew it would be something simple.

Thanks for your help! I really appreciate it.
 
wood burning stoves
 
subject: getClass().getClassLoader().getResource(path) always return null, even when the path is correct