Error creating excel file with java dependencie

三世轮回 提交于 2021-02-10 15:49:05

问题


I found dependencies from here : https://poi.apache.org/download.html

and the compilation was done at intellij idea without any error and my programm runs fine but when it tries to create the .xlsx file it gives this 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:102)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:124)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1373)
at com.company.Main.createexcel(Main.java:321)
at com.company.Main.main(Main.java:288)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.util.ArithmeticUtils
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 9 more

It sais that a class not found butno errors in the compilation what i'm doing wrong???

basically the error is at this command:

workbook.write(fos);

when creating the file

all the import statements are done correctly and intellij idea doesnt print any other errors imports:

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

My code is pretty simple simple i just tried to create a single sell to test it:

  static void createexcel(String[][] job) throws FileNotFoundException {
    try {
        String filename = "!..path..!/fil.xlsx";
        FileOutputStream fos = new FileOutputStream(filename);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("FirstSheet");
        sheet.createRow(0).createCell(0).setCellValue(0);
        workbook.write(fos);
        fos.close();
        workbook.close();
        System.out.println("Your excel file has been generated!");
    }catch (Exception e){
        System.out.println(e);
    }
}

I actually add the dependencies as I did with others in IntelliJ by going to: File>Project structure>Modules>Dependencies>”+” and selected the jar from the website

What went wrong ?


回答1:


Did you import library and add necessary jar files to project ? You should share your piece of code with import statements at top of the code.



来源:https://stackoverflow.com/questions/64666494/error-creating-excel-file-with-java-dependencie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!