Reputation: 13
I get NoClassDefFoundError error when I try run below code. I checked tons of similar posts, but it didn't helped. What do I wrong? I think, there is something with FileOutputStream but I don't know what.
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Vienna");
File viennaBatch = new File("C:\\Users\\majan\\Desktop\\CitiJanus\\Vienna.xls");
viennaBatch.createNewFile();
Row row = sheet.createRow(1);
Cell cell = row.createCell(1);
cell.setCellValue("a");
FileOutputStream fileOut
= new FileOutputStream("C:\\Users\\majan\\Desktop\\CitiJanus\\Vienna.xls");
workbook.write(fileOut);
fileOut.close();
}
}```
error:
```Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/util/ArithmeticUtils
at org.apache.poi.poifs.property.RootProperty.setSize(RootProperty.java:59)
at org.apache.poi.poifs.property.DirectoryProperty.<init>(DirectoryProperty.java:52)
at org.apache.poi.poifs.property.RootProperty.<init>(RootProperty.java:31)
at org.apache.poi.poifs.property.PropertyTable.<init>(PropertyTable.java:58)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:99)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:121)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1357)
at Main.main(Main.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.util.ArithmeticUtils
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 8 more```
Upvotes: 0
Views: 375
Reputation: 18067
Quote from the POI page:
Apache commons-math3 and commons-compress were added as a dependency in POI 4.0.0. Zaxxer SparseBitSet was added as a dependency in POI 4.1.2
The exception you're getting indicates that commons-math3 is missing in the classpath.
Upvotes: 2