我正在尝试使用 java 获取一些天气数据。我正在使用以下 java api 从 wunderground.com 获取数据
https://code.google.com/p/wunderground-core/
他们在其网站上提供的示例代码适用于(德国的多特蒙德)。但是,当我将密钥从美国的多特蒙德更改为波士顿时,出现空指针错误。知道我做错了什么吗?请尝试并留下评论/建议。谢谢!
代码:
import de.mbenning.weather.wunderground.api.domain.DataSet;
import de.mbenning.weather.wunderground.api.domain.WeatherStation;
import de.mbenning.weather.wunderground.api.domain.WeatherStations;
import de.mbenning.weather.wunderground.impl.services.HttpDataReaderService;
public class weather {
public static void main(String[] args)
{
// create a instance of a wunderground data reader
HttpDataReaderService dataReader = new HttpDataReaderService();
// select a wunderground weather station (ID "INORDRHE72" = Dortmund-Mengede)
WeatherStation weatherStation = WeatherStations.ALL.get("INORDRHE72");
// KMABOSTO22 is the ID for Boston South end
//WeatherStation weatherStation = WeatherStations.ALL.get("KMABOSTO32");
// set selected weather station to data reader
dataReader.setWeatherStation(weatherStation);
// get current (last) weather data set from selected station
DataSet current = dataReader.getCurrentData();
// print selected weather station ID
System.out.println(weatherStation.getStationId());
// print city, state and country of weather station
System.out.println(weatherStation.getCity() + " " + weatherStation.getState() + " " + weatherStation.getCountry());
//`enter code here` print datetime of measure and temperature ...
System.out.println(current.getDateTime() + " " + current.getTemperature());
}
}