user2065929 user2065929 - 1 year ago 197
Java Question

getClassLoader().getResourceAsStream("../resources/") returns null

Hi all i am getting the error

Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(
at java.util.Properties.load0(
at java.util.Properties.load(
at richard.fileupload.FileUploadController.loadProp(
... 60 more

whenever my properties class is called, this is the code

private Properties configProp = new Properties();

public void loadProp() {
System.out.println("Loading properties");
InputStream in = this.getClass().getClassLoader().getResourceAsStream("../resources/");
try {
} catch (IOException e) {
private String destinationPDF = configProp.getProperty("destinationPDF");
public String destination = configProp.getProperty("destination");
private String username;

the error seems to be coming from this line :

InputStream in = this.getClass().getClassLoader().getResourceAsStream("../resources/");
try {

what is causing this error and how can i solve it ?

the code above, should point to the properties file and then retrive the three variables values from it, it is not getting as far as the


before i get the error

this is my directory structure

enter image description here

as you can see the properties file is in resources/, how would i get a link to this


ok so it works perfectly fine with the full link to the file :

configProp.load(new FileInputStream("D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/WEB-INF/"));

but no matter where i put the file in the projet i can not get it to load at all, why is this ?

Answer Source

This line doesn't make sense:


ClassLoader.getResourceAsStream() loads a resource from the classpath, using a package path starting at the root package. And there is nothing above the root package.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download