java.lang.ClassNotFoundException : org. apache.xmlbeans.XmlObject 错误

标签 java

我收到以下错误

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject at OrderBook.WriteToExcelSheet.CreateOutPutFile(WriteToExcelSheet.java:20) at OrderBook.MainMethod.main(MainMethod.java:71)

我在网上查找了这个错误的原因,但找不到我得到它的原因。

我已包含以下 jar 文件

poi-3.9-20121203.jar, 
poi-excelant-3.9-20121203.jar,
poi-examples-3.9-20121203.jar,
poi-ooxml-3.9-20121203.jar,
poi-ooxml-schemas-3.9-20121203.jar,
poi-scratchpad-3.9-20121203.jar

代码:

public class WriteToExcelSheet {
    public static Map < Integer, Object[] > data = new TreeMap < Integer, Object[] > ();
    public static void CreateOutPutFile() {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Orderbook Stats");
        //This data needs to be written (Object[])
        //Iterate over data and write to sheet
        Set < Integer > keyset = data.keySet()
        int rownum = 0;
        for (Integer key: keyset) {
            Row row = sheet.createRow(rownum++);
            Object[] objArr = data.get(key);
            int cellnum = 0;
            for (Object obj: objArr) {
                Cell cell = row.createCell(cellnum++);
                if (obj instanceof String) cell.setCellValue((String) obj);
                else if (obj instanceof Integer) cell.setCellValue((Integer) obj);
            }
        }
        try {
            //Write the workbook in file system
            System.out.println("OutPutStats.xlsx writing..............................");
            FileOutputStream out = new FileOutputStream(new File("FileLocation/o.xlxs"));
            workbook.write(out);
            out.close();
            System.out.println("OutPutStats.xlsx written successfully on disk.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}    

最佳答案

您必须再添加一个 jar 。

xmlbeans-2.3.0.jar

添加并尝试。

注意:只有 .xlsx 格式的文件才需要,而不仅仅是 .xls 格式的文件。

关于java.lang.ClassNotFoundException : org. apache.xmlbeans.XmlObject 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19739026/

相关文章:

java - Android 的语音认证库

java - OpenXava - 创建包含所有模块的列表

java - 如何在执行时仅包含某些Java类 "gradle test"

java - KeyListener 仅在单击 Canvas 后才激活

Java:整数 obj 无法转换为 Comparable

java - 这段代码有什么错误?数据库中发现重复记录。

java - jmx 传递字符串数组

java - Hibernate 与 createCriteria 和 createAlias 的关联

java - 如何从 OutputStream 获取字节 [ ] 来检索上传的文件

java - 运行时编辑并保存其他 jar