我得到一個空指針異常,但我不知道爲什麼。我在查看字符串之前檢查了單元格是否爲空。那麼,爲什麼這個字符串爲空?空指針異常
private void fillArray()
{
try
{
readBook = new HSSFWorkbook(readFile);
}
catch (IOException e)
{
System.out.println("If we know what we're doing, no one should ever see this line.");
}
if (readBook != null)
{HSSFSheet infoSheet = readBook.getSheetAt(0);
HSSFRow headingsRow = infoSheet.getRow(0);
int i = 0;
HSSFCell cell = headingsRow.getCell(i);
String columnHeading = cell.toString();
while (cell != null && !(cell.toString().equals("")))
{
cell = headingsRow.getCell(i);
columnHeading = cell.toString();
columnHeadings.add(columnHeading);
i++;
}
if(columnListIsSetup == false)
{
createList();
columnListIsSetup = true;
}
}
有很多地方是*可能*扔NullPointerException異常 - 什麼堆棧跟蹤說? – 2012-07-06 21:10:37
它追溯到行columnHeading = cell.toString(); – user1507835 2012-07-06 21:18:09
然後顯示'cell'爲空......或者它在'toString'內被拋出。 – 2012-07-06 21:19:01