我尝试将字符串数组转换为双精度数组,具体取决于从数据库中选择的气象站 - 有些气象站没有数据,所以整个字符串数组都填充了空值(实际上是 12 个)所以很明显如果一个其中车站被选择我得到一个例外。我真的没有时间写很多代码来解决它,因为我必须很快提交我的工作......有什么解决方案可以捕捉它并向用户显示错误消息,其中包含解释错误的行和行? 谢谢!
这是将字符串数组转换为双精度数组的循环
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]);
}