Java8 FileSystems.getDefault()抛出由WindowsPathParser中的NullPointerException引起的ExceptionInInitializerError错误

Java8 FileSystems.getDefault()抛出由WindowsPathParser中的NullPointerException引起的ExceptionInInitializerError错误,java,java-8,filesystems,Java,Java 8,Filesystems,对path.get()的简单调用将抛出由WindowsPathParser中的NullPointerException引起的ExceptionInInitializeError。我在Windows7 Enterprise上使用Oracle jdk 1.8.013164位 static Path outPath; public static void main(String[] args) { outPath = Paths.get("data"); } 异常堆栈跟踪 Exceptio

对path.get()的简单调用将抛出由WindowsPathParser中的NullPointerException引起的ExceptionInInitializeError。我在Windows7 Enterprise上使用Oracle jdk 1.8.013164位

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)
线程“main”java.lang.ExceptionInInitializeError中的异常 位于java.nio.file.FileSystems.getDefault(FileSystems.java:176) 位于java.nio.file.Paths.get(path.java:84) 位于com.xpo.or.agg.specific.Program.instantiate(Program.java:62) 位于com.xpo.or.agg.specific.Program.main(Program.java:32) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中 位于java.lang.reflect.Method.invoke(Method.java:498) 位于com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 原因:java.lang.NullPointerException 位于sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:98) 位于sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) 位于sun.nio.fs.WindowsFileSystem.(windowsfystem.java:57) 位于sun.nio.fs.WindowsFileSystemProvider。(WindowsFileSystemProvider.java:53) 位于sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:36) 位于java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108) 位于java.nio.file.FileSystems$DefaultFileSystemHolder.access$000(FileSystems.java:89) 位于java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:98) 位于java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:96) 位于java.security.AccessController.doPrivileged(本机方法) 位于java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:96) 位于java.nio.file.FileSystems$DefaultFileSystemHolder。(FileSystems.java:90) 我能想到的唯一问题是静态成员程序类初始化和java.nio.file.FileSystems初始化之间的一些副作用

java.lang.ExceptionInInitializerError表示静态初始值设定项中发生意外异常。 将抛出一个
异常InInitializeRerror
,以指示 在计算静态初始值设定项或 静态变量的初始值设定项


非常感谢您的帮助。

嗯。。。我认为问题在于由于某种原因,
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是你的问题。

谢谢你的提示,Lachezar。当我在IntelliJ IDEA之外以jar应用程序的形式运行代码时,问题仍然存在。选中“user.dir”属性的值。它被设置为IDEA内部的项目根。因此,如果打印,例如:
System.out.prrintln(System.getProperty(“user.dir”))
就在
outPath=path.get(“data”)
之前,它会打印项目根:
C:\usr\prj\bla bla
。我已经设法将问题缩小到几行代码,并将根据调查结果更新这篇文章。你是对的。在一些自行开发的库中,会调用初始化
System.setProperties(config)
,从而允许调用
user.dir='null'
。感谢您提供明确的信息,在哪里查找问题!向系统添加自定义配置的正确方法:
Properties allProps=system.getProperties();allProps.putAll(appConfig);系统设置属性(allProps)