我正在努力從讀取xlsx文件中的錯誤。我正在使用poi 3.9-2012。 我的構造函數和其他方法的代碼是:java.util.NoSuchElementException - 在XSSFSheet上讀取
public students(String studentsDb){
this.location = studentsDb;
this.location = studentsDb;
studentInfoDB = new HashSet<Student>();
DBSetUp(location);
}
private void DBSetUp(String location) {
try {
this.location = location;
FileInputStream file = new FileInputStream(new File(location));
workbook = new XSSFWorkbook(file);
setUpStudent();
setUpTeam();
} catch (FileNotFoundException e) {
System.out.println("Failed To Find The File!");
} catch (IOException e) {
System.out.println("Failed To Create Workbook!");
}
}
private void setUpTeam() {
XSSFSheet sheet = workbook.getSheetAt(1);
Iterator<Row> rowIterator = sheet.iterator();
rowIterator.next();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
Cell cell = cellIterator.next();
String tempTeam = cell.getStringCellValue();
while (cellIterator.hasNext()) {
cell = cellIterator.next();
String tempName = cell.getStringCellValue();
for (Student s : studentInfoDB) {
if (s.getName().equals(tempName)) {
s.setTeam(tempTeam);
}
}
}
}
}
當我調用構造函數的學生(的位置)。蝕的java總是產生以下錯誤消息
java.util.NoSuchElementException在 java.util.TreeMap中$ PrivateEntryIterator.nextEntry(unknon源)在 java.util.TreeMap中$ ValueIterator.next(未知源)在 Students.setUpTeam(Students.java:77)在 Students.DBSetUp(Students.java:56)在 學生。(Students.java:39)
謝謝你的回答。我改變了這一點。這是工作。然而。當我在Excel中添加更多工作表並添加名爲setUpStudent(1)的其他方法時。收到了同樣的錯誤。哪裏不對了? – user3842385