对Paths.get()的简单调用会引发由WindowsPathParser中的NullPointerException引起的ExceptionInInitializerError。我在1.8.0_131企业上使用Oracle 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)我能想到的唯一问题是静态成员程序类初始化和java.nio.file.FileSystems初始化之间的一些副作用。
java.lang.ExceptionInInitializerError表示静态初始化程序中发生了意外异常。引发ExceptionInInitializerError以指示在计算静态初始化程序或静态变量初始化程序时发生异常。
任何帮助都是非常感谢的。
发布于 2017-05-26 07:01:15
嗯..。我认为问题在于,由于某种原因,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中配置(Mis)。无论如何,一个缺失的user.dir是你的问题。
https://stackoverflow.com/questions/44188542
复制相似问题