java.lang.ClassNotFoundException:org.apache.xmlbeans.XmlObject错误 [英] java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject Error

查看:136
本文介绍了java.lang.ClassNotFoundException:org.apache.xmlbeans.XmlObject错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下错误

线程"main"中的异常java.lang.NoClassDefFoundError:org/apache/xmlbeans/XmlObject 在OrderBook.WriteToExcelSheet.CreateOutPutFile(WriteToExcelSheet.java:20) 在OrderBook.MainMethod.main(MainMethod.java:71)

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)

我在线查找了此错误的原因,但找不到我为什么得到它.

I looked for the reasons for this error online but couldn't find why I am getting it.

我包含了以下jar文件

I have included the following jar files

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.

You have to include one more jar.

xmlbeans-2.3.0.jar

添加并尝试.

注意:仅对于.xlsx格式的文件是必需的,而不仅仅是.xls格式的文件.

Note: It is required for the files with .xlsx formats only, not for just .xls formats.

这篇关于java.lang.ClassNotFoundException:org.apache.xmlbeans.XmlObject错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆