我正在用OWM-JAPI在Java上编写天气应用程序(https://github.com/iamashks/OWM-JAPIs)。试着了解天气(如晴天、阴天等(,但我遇到了一些问题。
getCity().getWeatherList()
显示[Weather(conditionId=801, mainInfo=Clouds, moreInfo=небольшая облачность, iconCode=02d)]
我需要在moreInfo
中获取信息。
我该怎么做?谢谢
附言:如果你想要的话,我可以把我所有的项目都发到github上。
这是我的代码:
import net.aksingh.owmjapis.core.OWM;
import net.aksingh.owmjapis.api.APIException;
import net.aksingh.owmjapis.model.CurrentWeather;
public class Main {
// configure owm: api key, lang, accuracy, etc
private static OWM config(){
OWM owm;
owm = new OWM("061c88a24ac0ad18ae22534accea424a");
owm.setUnit(OWM.Unit.METRIC);
owm.setLanguage(OWM.Language.RUSSIAN);
owm.setAccuracy(OWM.Accuracy.ACCURATE);
return owm;
}
// getting city class
private static CurrentWeather getCity() throws APIException {
CurrentWeather cwd;
cwd = config().currentWeatherByCityName("Stupino");
return cwd;
}
// getting temperature
private static int getTemperature() throws APIException, NullPointerException{
int temp;
temp = (int)Math.round(getCity().getMainData().getTemp());
return temp;
}
// getting weather time
private static String getTime() throws APIException {
String time;
int hours, minutes, seconds;
hours = getCity().getDateTime().getHours();
minutes = getCity().getDateTime().getMinutes();
seconds = getCity().getDateTime().getSeconds();
time = hours + ":" + minutes + ":" + seconds + ".";
return time;
}
// sending weather info to user
private static void message() throws APIException {
String msgTime, msgCity, msgTemp, msgWeather;
msgTime = "Погода на " + getTime();
msgCity = "Город: " + getCity().getCityName();
msgTemp = "Температура: " + getTemperature() + "°C.";
System.out.println(msgTime + "n" +
msgCity + "n" +
msgTemp);
}
public static void main(String[] args) throws APIException, NullPointerException{
message();
}
}
调用列表第一个元素上的getMoreInfo:
getCity().getWeatherList().get(0).getMoreInfo()