我在启动项目时遇到了一些严重的困难。我有以下代码:
FileInputStream file = new FileInputStream(new File("src/retestchecker/test_sheet.xlsx"));
//Get the workbook instance for XLS file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(0);
Cell x = row.getCell(3);
System.out.println(x);
我收到此错误,但我不确定这意味着什么:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException
at retestchecker.RetestChecker.main(RetestChecker.java:23)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Java Result: 1
我正在使用 Netbeans 和 2015 年 5 月 11 日发布的最新版本的 Apache POI。
错误引用的第23行是这一行:
XSSFWorkbook workbook = new XSSFWorkbook(file);
我做错了什么?
最佳答案
您缺少 xmlbeans jar(可能还有更多)
Apache POI 有 handy page describing all of the components and their dependencies ,或者如果您使用 Maven,一切都会为您处理
在二进制版本中,您将在 ooxml-lib
子目录中找到 xmlbean。添加该内容以及任何其他 jar needed for the components you're using到你的类路径
关于使用 Apache POI 的 Java 程序给我带来奇怪的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30224826/