Java 错误消息:文件“";countries.geo.json“;丢失或无法访问

Java 错误消息:文件“";countries.geo.json“;丢失或无法访问,java,processing,Java,Processing,我正在上Java课程中的OOP。在模块4作业中,我运行课程在EarthquakeCityMap.java中提供的代码, 我得到一个错误,因为“文件”countries.geo.json“丢失或无法访问,请确保URL有效,或者该文件已添加到草图中并且可读。 线程“动画线程”java.lang.NullPointerException中出现异常 我试图将countryFile设置为 “./data/countries.geo.json”, “data/countries.geo.json”, 以及国

我正在上Java课程中的OOP。在模块4作业中,我运行课程在EarthquakeCityMap.java中提供的代码, 我得到一个错误,因为“文件”countries.geo.json“丢失或无法访问,请确保URL有效,或者该文件已添加到草图中并且可读。 线程“动画线程”java.lang.NullPointerException中出现异常

我试图将countryFile设置为 “./data/countries.geo.json”, “data/countries.geo.json”, 以及国家文件的完整路径, 但仍然没有解决问题

//this error points to the code
private String countryFile = "countries.geo.json";
List<Feature> countries = GeoJSONReader.loadData(this, countryFile);"

//the countries file is saved in data folder.
//此错误指向代码
私有字符串countryFile=“countries.geo.json”;
List countries=GeoJSONReader.loadData(这是countryFile);"
//国家/地区文件保存在数据文件夹中。
项目文件夹列表


如果指定了完整路径,但它不起作用,则可能忘记了用另一个反斜杠转义\字符。反斜杠字符是特殊的,需要加倍才能正确解释windows路径。例如“c:\\users\\\…”。您还可以指定/而不是\并且可以使用:“c:/users/…”

也就是说,文件的路径分辨率是相对的(即不是绝对的文件系统根)相对于已执行应用程序的工作目录。通常,在没有任何特殊配置的IDE中,工作目录将是项目的根路径。因此,为了正确解析相对文件路径,必须将路径指定为“data/countries.geo.json”

您还可以通过执行System.out.println(新的java.io.File(“.”.getAbsolutePath())来找出运行应用程序时所处的路径,并根据此文件夹创建相对路径。

“countries.geo.json”
(除非在
GeoJSONReader
中更改此路径)将与IntelliJ的项目
out
文件夹中编译的java.class文件相关

如果
GeoJSONReader.loadData(this,countryFile);
中的
this
是一个
PApplet
实例,您可以使用它相对于运行草图的文件夹创建路径:

List<Feature> countries = GeoJSONReader.loadData(this, this.sketchPath("data"+File.separator+countryFile));

我相信这个错误,并找出该文件所在的位置。运行代码时,当前目录是什么?指向
countries.geo.json
的路径必须与该目录相关。您可以发布一个吗?请不要添加不相关的标记。
String fullJSONPath = dataPath("countries.geo.json");
println("fullJSONPath: " + fullJSONPath);//hopefully this prints the full path to the json file on your machine
println(new File(fullJSONPath).exists());//hopefully this prints true