我正在使用 OWM-JAPI ( https://github.com/iamashks/OWM-JAPIs ) 在 Java 上撰寫 Weather App。試圖獲得天氣(如晴天、多云等),但我遇到了一些問題。
getCity().getWeatherList()
節目[Weather(conditionId=801, mainInfo=Clouds, moreInfo=небольшая облачность, iconCode=02d)]
我需要獲取資訊moreInfo。
我怎樣才能做到這一點?謝謝。
PS 如果你想要的話,我可以把我所有的專案都發到 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();
}
}
uj5u.com熱心網友回復:
在串列的第一個元素上呼叫 getMoreInfo:
getCity().getWeatherList().get(0).getMoreInfo()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/445983.html
上一篇:從詹金斯成功構建后的錯誤行
