private void cleaner(Integer columnsCount, Integer rowsCount, Object object){
int firstColumn=0;
int firstRow=0;
XSSFSheet sheet = workBook.getSheetAt(0);
for (int lineId=firstRow;lineId<rowsCount;lineId++) {
XSSFRow row = sheet.getRow(lineId);
for (int columnId=firstColumn;columnId<columnsCount;columnId++){
row.createCell(columnId).setCellValue(object.toString()); }
}
}
我真的不明白这个逻辑。首先,我得到行,然后我正在尝试写入数据。我当然知道,我所有的数据都不为空。但是编译器说:
Exception in thread "main" java.lang.NullPointerException
at workhere.WriterXlsx.cleaner(WriterXlsx.java:75)
at workhere.WriterXlsx.<init>(WriterXlsx.java:19)
at workhere.Start.main(Start.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
WriterXlsx.java:75 :row.createCell(columnId).setCellValue(object.toString());
我开始这个方法:cleaner(30,30,"");