java를 사용하여 날씨 데이터를 가져 오려고합니다. 나는 그들이 자신의 웹 사이트에 제공 예제 코드 (독일 도르트문트) 괜찮 작동 wunderground.comjava 및 wunderground api를 사용하여 기상 데이터 가져 오기
https://code.google.com/p/wunderground-core/
에서 데이터를 가져 오는에 대해 다음 자바 API를 사용하고 있습니다. 그러나 미국에서 도르트문트에서 보스톤으로 키를 변경하면 널 포인터 오류가 발생합니다. 내가 뭘 잘못했는지 알기나 해? 그것을 시도하고 의견/조언을 남겨주세요. 감사!
코드 :
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());
}
}
합니다. 'WeatherStations.ALL'객체의 일부인지 확신 할 수 있습니까? 디버깅을 시도 했습니까? – t0mppa
보스턴에서 어떤 Station ID를 시도 했습니까? – Reda
KMABOSTO32 // WeatherStation weatherStation = WeatherStations.ALL.get ("KMABOSTO32"); – Ammar