2013-02-21 76 views
0

我试图使用Apache POI创建一个简单的工作簿,并得到以下errors.Using apchhe POI 3.9好心帮我摆脱这种感谢的简单工作簿。出错创建使用Apache POI

错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException 
    at xlscreate.xlsclass.main(xlsclass.java:24) 
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 

CODE:

import java.io.FileOutputStream; 
import org.apache.poi.ss.usermodel.Workbook; 
import org.apache.poi.xssf.usermodel.XSSFWorkbook; 
import java.io.InputStream; 






public class xlsclass { 

    public static void main(String[] args) throws Exception,Throwable{ 

      // Workbook wb = new HSSFWorkbook(); 
      // FileOutputStream fileOut = new FileOutputStream("workbook.xls"); 
      // wb.write(fileOut); 
      // fileOut.close(); 

      Workbook wb = new XSSFWorkbook(); 
      FileOutputStream fileOut = new FileOutputStream("c:/workbook.xlsx"); 
      wb.write(fileOut); 
      fileOut.close(); 


    } 
} 
+0

你有进口org.apache.xmlbeans.XmlException?我在代码中看不到这一点。 – 2013-02-21 11:48:41

回答

1

的Apache POI具有相关性。你需要查看它们并将它们添加到你的类路径中。其中一个依赖库中包含此异常类:org.apache.xmlbeans.XmlException。不确定哪一个。之后,其他答案包含提示代码中的实际错误。

+0

这是这一个:http://xmlbeans.apache.org/ – 2013-02-21 11:52:10

1

的Apache POI有a number of dependencies。 Apache POI的每个部分的依赖关系的完整列表are given on the website

如果您使用Maven作为构建工具,当您将代码定义为依赖于Apache POI(全部已定义)时,它将自动吸收依赖关系。如果你使用Eclipse的Ant或者,那么你应该download二进制(-bin-)封装的Apache POI的,然后你会发现在那里所有的依赖蓄势待发。

(为了您的特定错误,你缺少的xmlbeans罐子,但我怀疑你也可以缺少一些其他的事情,这就是第一个命中)