求大侠告诉我为什么我的这段读取excel表中内容的代码报错会是空指针啊
错误信息为:Exceptioninthread"main"java.lang.NullPointerExceptionatreadExcel.<init>(readExc...
错误信息为:
Exception in thread "main" java.lang.NullPointerException
at readExcel.<init>(readExcel.java:52)
at MainreadExcel.main(MainreadExcel.java:3)
代码为:
public class readExcel {
String filePath="档案2013.xls";
public readExcel(){
try {
Person person=new Person();
POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream(filePath));
HSSFWorkbook workbook=new HSSFWorkbook(fs);
HSSFSheet sheet=workbook.getSheetAt(68);
List<String> rows=new ArrayList<String>();
for (int RowNum = 0,j=sheet.getLastRowNum(); RowNum <=j; RowNum++) {
HSSFCell name=sheet.getRow(RowNum).getCell(0);
HSSFCell staffNo=sheet.getRow(RowNum).getCell(1);
HSSFCell company=sheet.getRow(RowNum).getCell(2);
HSSFCell sex=sheet.getRow(RowNum).getCell(3);
person.setName(name.getStringCellValue());
person.setStaffno(staffNo.getStringCellValue());
person.setCompany(company.getStringCellValue());
person.setSex(sex.getStringCellValue());
rows.add(person.getName());
rows.add(person.getStaffno())
rows.add(person.getCompany());
rows.add(person.getSex());
} 展开
Exception in thread "main" java.lang.NullPointerException
at readExcel.<init>(readExcel.java:52)
at MainreadExcel.main(MainreadExcel.java:3)
代码为:
public class readExcel {
String filePath="档案2013.xls";
public readExcel(){
try {
Person person=new Person();
POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream(filePath));
HSSFWorkbook workbook=new HSSFWorkbook(fs);
HSSFSheet sheet=workbook.getSheetAt(68);
List<String> rows=new ArrayList<String>();
for (int RowNum = 0,j=sheet.getLastRowNum(); RowNum <=j; RowNum++) {
HSSFCell name=sheet.getRow(RowNum).getCell(0);
HSSFCell staffNo=sheet.getRow(RowNum).getCell(1);
HSSFCell company=sheet.getRow(RowNum).getCell(2);
HSSFCell sex=sheet.getRow(RowNum).getCell(3);
person.setName(name.getStringCellValue());
person.setStaffno(staffNo.getStringCellValue());
person.setCompany(company.getStringCellValue());
person.setSex(sex.getStringCellValue());
rows.add(person.getName());
rows.add(person.getStaffno())
rows.add(person.getCompany());
rows.add(person.getSex());
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询