缺少JSONException类型:OpenWeatherMap中的方法引用了缺少的JSONException类型

时间:2019-05-11 05:52:55

标签: java json openweathermap

我正在为一个项目编程,并开始包含OpenWeatherMap API(版本:owm-japis-2.5.0.5.jar)。 因为我不是硬核开发人员,所以我使用以下描述:https://www.igorkromin.net/index.php/2017/01/01/a-simple-openweathermap-example-in-java/ 但是我有两个关于JSON的错误。 -项目找不到org.JSONException的类文件。它说要修复构建路径(构建路径请参见下文)。 -无法解析类型org.json.JSONException。从所需的.class文件中间接引用

我已经包含了API:Java Build Path并添加了“ JARs ...”。因此它已经在项目中并且在此JSON Exception之前可用。

boolean isMetric = true;
        String owmApiKey = "NOT_TYPED_IN_THERE_FOR_FORUM"; /* YOUR OWM API KEY HERE */
        String weatherCity = "Brisbane,AU";
        byte forecastDays = 3;

        OpenWeatherMap.Units units = (isMetric)
            ? OpenWeatherMap.Units.METRIC
            : OpenWeatherMap.Units.IMPERIAL;
        OpenWeatherMap owm = new OpenWeatherMap(units, owmApiKey);
        try {
            DailyForecast forecast = owm.dailyForecastByCityName(weatherCity, forecastDays);
            System.out.println("Weather for: " + forecast.getCityInstance().getCityName());
          int numForecasts = forecast.getForecastCount();
          for (int i = 0; i < numForecasts; i++) {
            DailyForecast.Forecast dayForecast = forecast.getForecastInstance(i);
            DailyForecast.Forecast.Temperature temperature = dayForecast.getTemperatureInstance();
            System.out.println("\t" + dayForecast.getDateTime());
            System.out.println("\tTemperature: " + temperature.getMinimumTemperature() +

                " to " + temperature.getMaximumTemperature() + "\n");
          }
        }
        catch (IOException | JSONException e) {
          e.printStackTrace();
        }

try语句之后的第一行给出了解释的错误。 有人可以帮我解决JSONException的问题吗?

最好,帕特里克

0 个答案:

没有答案