I'm working on a java application which is supposed to load in images from the same directory that the .jar file will be in. The code below is what I currently have, and it works fine in Windows (in the workspace I'm using and in the .jar file's directory, wherever I put it). However, when I try to run the .jar file in OS X, it doesn't work. I get a null pointer exception. Is there something that I'm missing? or some formatting thing I'm not aware of?
String dir = System.getProperty("user.dir");
File folder = new File(dir+"/");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String name = listOfFiles[i].getName();
String fileType = name.substring(name.length()-3, name.length());
if (fileType.equals("jpg")){
File file = new File(dir+"/"+name);
listMPs.add(new MusicPanel(file));
base.add(listMPs.get(count));
base.add(listMPs.get(count).switchLabel);
if(count==0){
base.add(listMPs.get(0).firstSwitchLabel);
}
assignIndexes();
assignMLs();
count++;
}
}
}