问题
I'm using Java to get the map between volume label and drive letter and the code is like below:
import java.io.File;
import javax.swing.filechooser.FileSystemView;
public class Test{
public void listMap(){
File[] files = File.listRoots();
System.out.println("The map between volume label and drive is: " );
for(File file: files){
String theMap = FileSystemView.getFileSystemView().getSystemDisplayName(file);
System.out.println(theMap);
}
}
public static void main(String[] args) {
Test test = new Test();
test.listMap();
}
}
I have built above code into a exe file on windows through exe4j. It works fine when you run it directly.
However, when I use Teamcity
build agent to launch the exe, the exception below will be thrown when the FileSystemView.getFileSystemView().getSystemDisplayName(file)
is called.
java.lang.NullPointerException
at sun.awt.shell.Win32ShellFolder2$1.call(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$1.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Any comment is appreciated.
来源:https://stackoverflow.com/questions/47616912/why-filesystemview-throw-npe-in-my-scenario