I'm new to Java and am trying to learn how to read/write to excel using the Apache POI. As of now, I am just trying to write a new excel file, but even after throwing the IO exception, I am getting a java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException exception.
Here is my code:
package ExcelDemo;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Demo {
public static void main (String[]args) throws IOException {
try {
XSSFWorkbook workbook = new XSSFWorkbook();
FileOutputStream out = new FileOutputStream(new File("C:/Users/colin/IdeaProjects/FinancialIndependence/src/ExcelDemo.xlsx"));
workbook.write(out);
out.close();
}
catch(Exception e){
System.out.println(e);
}
System.out.println("Excel file outputted");
}
}
Here is the error I am getting:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException at ExcelDemo.Demo.main(Demo.java:13) Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ... 1 more
Process finished with exit code 1