对Paths.get()的简单调用会抛出由WindowsPathParser中的NullPointerException引起的ExceptionInInitializerError。我在Windows7 Enterprise上使用Oracle jdk 1.8.0_131 64位。
static Path outPath;
public static void main(String[] args) {
outPath = Paths.get("data");
}
异常堆栈跟踪
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at java.nio.file.Paths.get(Paths.java:84)
at com.xpo.or.agg.specific.Program.instantiate(Program.java:62)
at com.xpo.or.agg.specific.Program.main(Program.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.NullPointerException
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:98)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsFileSystem.<init>(WindowsFileSystem.java:57)
at sun.nio.fs.WindowsFileSystemProvider.<init>(WindowsFileSystemProvider.java:53)
at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:36)
at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108)
at java.nio.file.FileSystems$DefaultFileSystemHolder.access$000(FileSystems.java:89)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:98)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:96)
at java.security.AccessController.doPrivileged(Native Method)
at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:96)
at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:90)
我能想到的唯一问题是静态成员Program类初始化和 java.nio.file.FileSystems 初始化之间的一些副作用。
java.lang.ExceptionInInitializerError表示静态初始值设定项中发生了意外异常。
抛出ExceptionInInitializerError
表示一个
在评估静态初始化程序或期间发生异常
静态变量的初始化程序。
感谢任何帮助。
答案 0 :(得分:2)
嗯......我认为问题在于user.dir
系统属性由null
出于某种原因。原因是(我猜)你的IDE配置中的某个地方。例如:
public static void main(String[] args) {
System.getProperties().remove("user.dir");
outPath = Paths.get("data");
}
将在不同环境中重现您的确切问题:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at java.nio.file.Paths.get(Paths.java:84)
我是Eclipse / STS用户,此属性来自应用程序的运行配置,但我不确定您如何(错误)在IntelliJ中配置它。无论如何 - 缺少user.dir
是你的问题。