【发布时间】:2020-05-06 19:58:16
【问题描述】:
public static void main(String [] args){
String excelFilePath = "D:\\JavaBooks.xls";
try {
FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0);
Object[][] bookData = {
{"The Passionate Programmer", "Chad Fowler", 16},
{"Software Craftmanship", "Pete McBreen", 26},
{"The Art of Agile Development", "James Shore", 32},
{"Continuous Delivery", "Jez Humble", 41},
};
int rowCount = sheet.getLastRowNum();
for (Object[] aBook : bookData) {
Row row = sheet.createRow(++rowCount);
int columnCount = 0;
Cell cell = row.createCell(columnCount);
cell.setCellValue(rowCount);
for (Object field : aBook) {
cell = row.createCell(++columnCount);
if (field instanceof String) {
cell.setCellValue((String) field);
} else if (field instanceof Integer) {
cell.setCellValue((Integer) field);
}
}
}
inputStream.close();
FileOutputStream outputStream = new FileOutputStream("D:\\JavaBooks.xls");
workbook.write(outputStream);
workbook.close();
outputStream.close();
} catch (IOException | EncryptedDocumentException
ex) {
ex.printStackTrace();
}
}
}
执行此代码时出现错误 线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/commons/math3/util/ArithmeticUtils 在 org.apache.poi.poifs.property.RootProperty.setSize(RootProperty.java:59) 在 org.apache.poi.poifs.property.DirectoryProperty.(DirectoryProperty.java:52) 在 org.apache.poi.poifs.property.RootProperty.(RootProperty.java:31) 在 org.apache.poi.poifs.property.PropertyTable.(PropertyTable.java:58) 在 org.apache.poi.poifs.filesystem.POIFSFileSystem.(POIFSFileSystem.java:102) 在 org.apache.poi.poifs.filesystem.POIFSFileSystem.(POIFSFileSystem.java:274) 在 org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:252) 在 org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:221) 在 NewClass.main(NewClass.java:31) 引起:java.lang.ClassNotFoundException:org.apache.commons.math3.util.ArithmeticUtils 在 java.net.URLClassLoader.findClass(URLClassLoader.java:381) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 9 更多
【问题讨论】:
-
您好,您可能需要查看this answer 和/或检查项目的依赖项(如果它们引用了
org.apache.commons::commons-math3::3.0工件) -
您是否在使用Maven、Gradle、Ivy等依赖管理工具?如果没有,那么推荐,正是出于这个原因。正如 Alex R 所提到的,在这个背后可能隐藏着额外的缺失依赖项。
标签: java excel apache-poi noclassdeffounderror