I have tried to write a simple code with Java FX to create an .xlsx file:
package apachepoi;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.Initializable;
import java.io.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ApachePOI_ViewController implements Initializable {
private void CreateWorkBook() {
try {
XSSFWorkbook workbook = new XSSFWorkbook();
FileOutputStream out = new FileOutputStream(new File("NewWorkBook.xlsx"));
workbook.write(out);
out.close();
System.out.println("NewWorkBook.xlsx written successfully.");
} catch (Exception ex) {
System.out.println(ex);
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
CreateWorkBook();
}
}
But I got this error:
I have googled this error:
java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap
and got these two StackOverflow threads:
Apache POI error loading XSSFWorkbook class
ListValuedMap NoClassDefFoundError when Reading Excel using Apache Poi?
I have read these from character to character, but importing commons-collections4-4.1.jar
file (actually I use 4.4 right now) didn't solve the Exception error.
My imported .jar files:
- poi-ooxml-4.1.2.jar
- commons-collections4-4.4.jar
- xmlbeans-3.1.0.jar
- dom4j-1.6.1.jar
What else should I do?