使用 Apache POI 的 Java 程序给我带来奇怪的异常

标签 java apache netbeans apache-poi

我在启动项目时遇到了一些严重的困难。我有以下代码:

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/

相关文章:

java - SWT 表查看器在行选择上添加复选框

Java Sound播放一次然后不再播放

Java 枚举矫枉过正?

java - 由 : java. lang.ClassNotFoundException : org. apache.chemistry.opencmis.server.shared.AbstractCmisHttpServlet 引起

python - 使用非默认 Apache Web 服务器编译 mod_wsgi?

java - 如何更改 Mavenized Netbeans 应用程序的图标

java - Java中如何返回多个类的数组列表?

apache - httpd 中的 SSLCACertificatePath

java - 无法使用 JDBC 连接到 Sql Server 数据库

java - 在 Netbeans 7.3.1 中解析文件 JSP 或 JAVA 时出错