gpt4 book ai didi

java - 尝试使用 Apache poi api 读取 Excel 工作表时出现 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-12-02 01:49:53 25 4
gpt4 key购买 nike

主机:Ubuntu 18.04 openjdk 10.0.2 2018-07-17

我尝试使用 Apache POI 从 Excel 工作表读取数据,但收到 NoClassDefFoundError。

这是我的代码:

package readatafromexcel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadExcel {

public static void main(String[] args) throws Throwable {
// TODO Auto-generated method stub

try{

//create file object
File src = new File("/home/nisha/Downloads/files/First/refdata.xlsx");

//create file Input stream object
FileInputStream reader =new FileInputStream(src);

//create workbook object
XSSFWorkbook wb =new XSSFWorkbook(reader);

//create sheet
XSSFSheet sheet1=wb.getSheetAt(0);


//fetch data from excel
String rowData =sheet1.getRow(0).getCell(0).getStringCellValue();

//print value
System.out.println("data"+rowData);
}

catch (FileNotFoundException e)
{

}



}

}

这是堆栈跟踪:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/compress/utils/InputStreamStatistics
at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.<init>(ZipArchiveThresholdInputStream.java:62)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipStream(ZipHelper.java:180)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:104)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:298)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307)
at readatafromexcel.ReadExcel.main(ReadExcel.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.utils.InputStreamStatistics
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 7 more

以下是链接到项目的库(使用 Eclipse IDE): enter image description here

enter image description here

编辑

将 Java 更改为 1.8 后,我现在收到此错误:

Exception in thread "main" java.lang.IllegalArgumentException: InputStream of class class org.apache.commons.compress.archivers.zip.ZipArchiveInputStream is not implementing InputStreamStatistics.
at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.<init>(ZipArchiveThresholdInputStream.java:63)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipStream(ZipHelper.java:180)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:104)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:298)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307)
at readatafromexcel.ExcelReadData.main(ExcelReadData.java:24)

最佳答案

Caused by: java.lang.ClassNotFoundException: org.apache.commons.compress.utils.InputStreamStatistics

我在引用的库列表中没有找到 commons-compress 库,因此请尝试添加 commons-compress 1.18作为依赖项

关于java - 尝试使用 Apache poi api 读取 Excel 工作表时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53142170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com