Hello I am currently processing a large Excel document containing the yearly temperatures of each of the world s cities over around 270 years and am receiving an error java.util.NoSuchElementException: No line found after around 75000 lines. Each line has 8 elements in them which get stored in an arraylist of type city which has variables: CountryName, CityName, AvgTemp, MinTemp, MaxTemp, Longitude, Latitude and Year. The method I am using to debug this is as follows:
private static void FillPopulation(){
Connection con = null;
try{
con = DriverManager.getConnection(DATA_BASE);
Scanner lineScanner = new Scanner(new File(EXCEL_TO_PROCESS));
lineScanner.nextLine();
while (lineScanner.hasNext()) {
String line = lineScanner.nextLine();
Scanner rowScanner = new Scanner(line);
rowScanner.useDelimiter(",");
String year = rowScanner.next();
String avgTemp = rowScanner.next();
String minTemp = rowScanner.next();
String maxTemp = rowScanner.next();
String cityName = rowScanner.next();
String countryName = rowScanner.next();
String latitude = rowScanner.next();
String longitude = rowScanner.next();
if (avgTemp.equals("")) {
avgTemp = "0";
}
if (minTemp.equals("")) {
minTemp = "0";
}
if (maxTemp.equals("")) {
maxTemp = "0";
}
String query = "INSERT INTO CityTemps VALUES( " + countryName + " , " + cityName + " , " + year +", "+avgTemp+", "+maxTemp+", "+minTemp+", "+latitude+" , "+longitude+" )" ;
System.out.println(query);
Statement stmt = con.createStatement();
stmt.execute(query);
}
}catch(Exception e){
e.printStackTrace();
}
}
不能确定造成这种情况的原因,我们非常赞赏任何解释。