You need to put 'logo.jpg' in the 'pics' directory,relative to the root of your CLASSPATH, otherwise, ClassLoader.getResource() will return null, resulting in NPE when you try to open an InputStream based on it.
So, using an eclipse workspace with this code...
import java.io.InputStream;
import java.net.URL;
public class GetResource {
public static void main(String[] args) throws Exception {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
URL resource = classLoader.getResource("pics/logo.jpg");
System.out.println("resource is " + resource);
InputStream inputStream = resource.openStream();
System.out.println("The inputStream was not null");
}
}
It will return...
resource is null
Exception in thread "main" java.lang.NullPointerException
at GetResource.main(GetResource.java:9)
if "pics/logo.jpg" is not found relative to CLASSPATH root. Create the "logo.jpg" file in the right location (in this case the "src/pics" folder of the Eclipse project, which will automatically put it into the "bin/pics" folder), and the output is...
resource is file:/home/joe/workspace/Play/bin/pics/logo.jpg
The inputStream was not null
Normally the resources would be bundled inside your jar, so the "logo.jpg" should be in the "/pics" directory at the root of the jar.