为了账号安全,请及时绑定邮箱和手机立即绑定

我在尝试使用提供的代码读取 Excel 文件时收到 Class Not Found 错误

我在尝试使用提供的代码读取 Excel 文件时收到 Class Not Found 错误

手掌心 2021-12-18 09:46:16
尝试读取 Excel 文件时出现以下错误:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook    at Caused by: java.lang.ClassNotFoundException: org.apache.poi.hssf.usermodel.HSSFWorkbook    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)    ... 2 more我使用以下代码读取扩展名为 .xls 的 Excel 文件。我曾尝试通过导入其他 poi jar 来寻找答案,但没有帮助,我已经检查了网络搜索,但再次没有帮助。public Object[][] getExcelData(String excelLocation, String sheetName) {        try {            Object dataSets[][] = null;            FileInputStream file = new FileInputStream(new File(excelLocation));HSSFWorkbook workbook = new HSSFWorkbook(excelLocation);HSSFSheet sheet = workbook.getSheet(sheetName);int totalRowNum = sheet.getLastRowNum();int totalColumnNum = sheet.getRow(0).getLastCellNum();dataSets = new Object[totalRowNum][totalColumnNum];Iterator<Row> rowIterator = sheet.iterator();            int i = 0;while (rowIterator.hasNext()) {                i++;HSSFRow row = (HSSFRow) rowIterator.next();                Iterator<Cell> cellIterator = row.cellIterator();                int j = 0;                while (cellIterator.hasNext()) {                    j++;                    HSSFCell cell = (HSSFCell) cellIterator.next();                    switch (cell.getCellTypeEnum()) {                    case STRING:                    dataSets[i][j] = cell.getStringCellValue();                        break;                    case NUMERIC:                        dataSets[i][j] = cell.getNumericCellValue();                        break;
查看完整描述

1 回答

?
呼如林

TA贡献1798条经验 获得超3个赞

从您的用户位置删除 .m2-> 执行 Maven 强制更新->运行


查看完整回答
反对 回复 2021-12-18
  • 1 回答
  • 0 关注
  • 434 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信