Your .getResource(filename) is probably returning a null
. You should test that url
has a value before using it; something like:
public static String fileToPath(String filename) throws UnsupportedEncodingException{
URL url = MainTestCharm_saveToMemory.class.getResource(filename);
if (url != null) {
return java.net.URLDecoder.decode(url.getPath(),"UTF-8");
}
System.out.println("file: " + filename + "not found");
System.exit(-1); // or return empty string or null
}
EDIT:
For getResource(filename)
to work outside the package, the filename should start with "/"; for example:
database.loadFile(fileToPath("/contextPasquier99.txt"));
If it's called like:
database.loadFile(fileToPath("contextPasquier99.txt"));
it will only look inside the package ca.pfv.spmf.test
.