Reputation: 33
I know there have been multiple posts on the subject but my issue seems to be one that hasn't been brought up yet. Under no circumstance can I seem to get getResource
to correctly return a path location. It got to the point where I try to find the current class' path and even that is giving me a null pointer exception. Here is a list of ways I have went about it.
testProject
lib
public class Klass
{
public void resourceTest()
{
ClassLoader.getSystemResource(Klass.class.getSimpleName() + ".class").toString();
Klass.class.getClass().getResource(Klass.class.getSimpleName() + ".class").toString();
Klass.class.getClass().getClassLoader().getResource(Klass.class.getSimpleName() + ".class").toString();
}
}
Please let me know if I'm doing anything wrong. I've used getResource
before so this is driving me crazy. Thanks!
Upvotes: 1
Views: 609
Reputation: 16364
Klass.class.getClass()
is equivalent to Class.class
, since the class of Klass.class
is Class
. So this would be trying to load a resource in the java.lang
package. You just want Klass.class.getResource()
.
Upvotes: 2
Reputation: 1166
There is a klass.class as last row. Try to use Klass.class with capital K
Upvotes: -1