错误信息:文件“countries.geo.json"丢失或无法访问 [英] Error message: The file "countries.geo.json" is missing or inaccessible

查看:69
本文介绍了错误信息:文件“countries.geo.json"丢失或无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在参加 Java 课程的 Coursera OOP.在模块4作业中,我运行了课程提供的EarthquakeCityMap.java中的代码,并且我收到错误消息文件countries.geo.json"丢失或无法访问,请确保 URL 有效或该文件已添加到您的草图中并且可以读取.线程动画线程"java.lang.NullPointerException 中的异常

I am taking the Coursera OOP in Java class. In the module 4 assignment, I run the code that the course provides in EarthquakeCityMap.java, and I get an error as "The file "countries.geo.json" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable. Exception in thread "Animation Thread" java.lang.NullPointerException"

我尝试将 countryFile 设置为"../data/countries.geo.json","数据/countries.geo.json",和国家文件的完整路径,但还是没有解决问题.

I tried to set countryFile as "../data/countries.geo.json", "data/countries.geo.json", and the complete path of countries file, but still didn't solve the problem.

//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.

项目文件夹列表

推荐答案

"countries.geo.json"(除非在 GeoJSONReader 中更改操作此路径)将是相对的到 IntelliJ 项目 out 文件夹中已编译的 java .class 文件.

"countries.geo.json" (unless changed in GeoJSONReader manipulates this path) will be relative to the compiled java .class files in the IntelliJ's project out folder.

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

If this in GeoJSONReader.loadData(this, countryFile); is a PApplet instance you can use sketchPath() to make that path relative to the folder from which the sketch runs:

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

以上代码段基于假设,因此您的代码中的语法可能略有不同,但希望这能说明您将如何使用 sketchPath().

The above snippet is based on an assumption so the syntax in your code might be slightly different, but hopefully this illustrates how you'd use sketchPath().

另外还有一个 dataPath() 以及您可以从 setup() 中的主 PApplet 进行测试的测试:

Additionally there's a dataPath() as well which you can test from your main PApplet in setup() as a test:

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

这篇关于错误信息:文件“countries.geo.json"丢失或无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆