0
根據從數據庫中選擇的氣象站,我嘗試將字符串數組轉換爲雙精度數組 - 一些氣象站沒有數據,因此整個字符串數組是充滿了空值(實際上其中12個)因此,如果選擇其中一個電臺,我會得到一個例外。我真的沒有時間寫很多代碼來解決它,因爲我必須很快提交我的工作......是否有任何解決方案來捕捉它並向用戶顯示一條錯誤消息insted的行和行解釋錯誤?謝謝!在將字符串轉換爲雙精度時檢查java中的錯誤
這裏是循環的字符串數組轉換爲雙陣列
for(int i = 0; i<12; i++)
{
avMaxTempOptimised[i] = Double.parseDouble(avMaxTempSplit[i]);
avMinTempOptimised[i] = Double.parseDouble(avMinTempSplit[i]);
meanTempOptimised[i] = Double.parseDouble(meanTempSplit[i]);
highestTempOptimised[i] = Double.parseDouble(highestTempSplit[i]);
lowestTempOptimised[i] = Double.parseDouble(lowestTempSplit[i]);
maxWindOptimised[i] = Double.parseDouble(maxWindSplit[i]);
totalRainfallOptimised[i] = Double.parseDouble(totalRainfallSplit[i]);
maxDayRainfallOptimised[i] = Double.parseDouble(maxDayRainfallSplit[i]);
rainDaysOptimised[i] = Double.parseDouble(rainDaysSplit[i]);
totalSunshineOptimised[i] = Double.parseDouble(totalSunshineSplit[i]);
mostSunshineDayOptimised[i] = Double.parseDouble(mostSunshineDaySplit[i]);
avMaxTemp2Optimised[i] = Double.parseDouble(avMaxTemp2Split[i]);
avMinTemp2Optimised[i] = Double.parseDouble(avMinTemp2Split[i]);
meanTemp2Optimised[i] = Double.parseDouble(meanTemp2Split[i]);
highestTemp2Optimised[i] = Double.parseDouble(highestTemp2Split[i]);
lowestTemp2Optimised[i] = Double.parseDouble(lowestTemp2Split[i]);
maxWind2Optimised[i] = Double.parseDouble(maxWind2Split[i]);
totalRainfall2Optimised[i] = Double.parseDouble(totalRainfall2Split[i]);
maxDayRainfall2Optimised[i] = Double.parseDouble(maxDayRainfall2Split[i]);
rainDays2Optimised[i] = Double.parseDouble(rainDays2Split[i]);
totalSunshine2Optimised[i] = Double.parseDouble(totalSunshine2Split[i]);
mostSunshineDay2Optimised[i] = Double.parseDouble(mostSunshineDay2Split[i]);
}
我不明白,你想做什麼,當你遇到一個null,你想打印一個錯誤?或者你想保存0嗎?一個-1? – jsedano
是的,我想打印en錯誤,我認爲它甚至不是0 - 如果它是我不會得到一個錯誤,它是NULL –
而NULL不能轉換爲雙重 –