gpt4 book ai didi

Java - 加载文件时出现问题 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-12-01 11:21:32 25 4
gpt4 key购买 nike

已解决:我需要添加另一个文件夹中的另一个 jar 文件

我的所有代码都在下面。来自this网站。我已经阅读了多个加载 XSSF 文件的示例,但我仍然遇到同样的错误。我的所有导入都是正确的,但我唯一的猜测是我的文件路径。但这似乎是正确的并且没有给我任何错误

package testcode;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;


import java.util.Iterator;

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

public class TestCode {

public static void main( String[] args ) throws IOException {
InputStream ExcelFileToRead = new FileInputStream("C:/Users/[name]/Desktop/Book1.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);

XSSFWorkbook test = new XSSFWorkbook();

XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow row;
XSSFCell cell;

Iterator rows = sheet.rowIterator();

while ( rows.hasNext() ) {
row = ( XSSFRow ) rows.next();
Iterator cells = row.cellIterator();
while( cells.hasNext() ) {
cell = ( XSSFCell ) cells.next();

if ( cell.getCellType() == XSSFCell.CELL_TYPE_STRING ) {
System.out.print( cell.getStringCellValue() + " " );
}
else if( cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC ) {
System.out.print( cell.getNumericCellValue() + " " );
}
else {

}
}
System.out.println();
}
}

错误消息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException at testcode.TestCode.main(TestCode.java:20) Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more

最佳答案

NoClassDefFoundError 。当您的代码依赖的类文件或api在编译时存在但在运行时找不到时,就会遇到此异常。请检查运行时可用的 jar 或比较运行时和编译依赖项。

关于Java - 加载文件时出现问题 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31170027/

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