gpt4 book ai didi

java - 线程 "main"java.lang.NoClassDefFoundError : org/apache/xmlbeans/XmlException 中的异常

转载 作者:太空狗 更新时间:2023-10-29 22:42:41 24 4
gpt4 key购买 nike

我必须在 java 中读取 xls 文件。我使用 poi-3.6 在 Eclipse 中读取 xls 文件。但我收到此错误“线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/xmlbeans/XmlException 在 ReadExcel2.main(ReadExcel2.java:38)”。

我添加了以下 jar 1)poi-3.6-20091214.jar2)poi-contrib-3.6-20091214.jar3)poi-examples-3.6-20091214.jar4)poi-ooxml-3.6-20091214.jar5)poi-ooxml-schemas-3.6-20091214.jar6)poi-scratchpad-3.6-20091214.jar

下面是我使用的代码:

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
public class ReadExcel {

public static void main(String[] args) throws Exception {
//
// An excel file name. You can create a file name with a full path
// information.
//
String filename = "C:\\myExcel.xl";
//
// Create an ArrayList to store the data read from excel sheet.
//
List sheetData = new ArrayList();

FileInputStream fis = null;
try {
//
// Create a FileInputStream that will be use to read the excel file.
//
fis = new FileInputStream(filename);

//
// Create an excel workbook from the file system.
//
// HSSFWorkbook workbook = new HSSFWorkbook(fis);
Workbook workbook = new XSSFWorkbook(fis);

//
// Get the first sheet on the workbook.
//
Sheet sheet = workbook.getSheetAt(0);

//
// When we have a sheet object in hand we can iterator on each
// sheet's rows and on each row's cells. We store the data read
// on an ArrayList so that we can printed the content of the excel
// to the console.
//
Iterator rows = sheet.rowIterator();
while (rows.hasNext()) {
Row row = (XSSFRow) rows.next();
Iterator cells = row.cellIterator();

List data = new ArrayList();
while (cells.hasNext()) {
Cell cell = (XSSFCell) cells.next();
data.add(cell);
}

sheetData.add(data);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
fis.close();
}
}

showExelData(sheetData);
}
private static void showExelData(List sheetData) {
//
// Iterates the data and print it out to the console.
//
for (int i = 0; i < sheetData.size(); i++) {
List list = (List) sheetData.get(i);
for (int j = 0; j < list.size(); j++) {
Cell cell = (XSSFCell) list.get(j);
System.out.print(cell.getRichStringCellValue().getString());
if (j < list.size() - 1) {
System.out.print(", ");
}
}
System.out.println("");
}
}
}

请帮忙。感谢期待,问候,Dheeraj!

最佳答案

你需要xmlbeans在你的类路径上。

NoClassDefFoundError意味着:

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

所以下次你遇到这样的异常时,这意味着某个第 3 方库需要另一个第 3 方库。然后使用谷歌(或任何其他方式)查找这是哪个库。此外,大多数库在其文档和/或发行版中清楚地说明了它们的依赖项。

关于java - 线程 "main"java.lang.NoClassDefFoundError : org/apache/xmlbeans/XmlException 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2673237/

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