【问题标题】:Java Program using Apache POI giving me weird Exceptions使用 Apache POI 的 Java 程序给了我奇怪的异常
【发布时间】:2015-05-13 20:42:19
【问题描述】:

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

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);

我做错了什么?

【问题讨论】:

  • 似乎您的类路径中没有所有必需的库。例如,如果您还没有尝试过 Maven,您可能想尝试一下。

标签: java apache netbeans apache-poi


【解决方案1】:

您缺少 xmlbeans jar(可能还有更多)

Apache POI 有一个 handy page describing all of the components and their dependencies,或者如果您使用 Maven,一切都会为您处理好

在二进制版本中,您会在 ooxml-lib 子目录中找到 xmlbeans。将它和任何其他 jars needed for the components you're using 添加到您的类路径中

【讨论】:

    【解决方案2】:

    这意味着编译器找不到名为 org.apache.xmlbeans.XmlException 的类 您必须找到 apache poi 的哪些 .jar 文件定义它并将它们添加到项目的类路径中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 2011-11-16
      • 1970-01-01
      相关资源
      最近更新 更多