Java程序使用Apache POI让我奇怪的例外 [英] Java Program using Apache POI giving me weird Exceptions

查看:113
本文介绍了Java程序使用Apache POI让我奇怪的例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有让我的项目离地面一些严重的困难。我有以下的code:

I am having some serious difficulty getting my project off the ground. I have the following code:

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

我得到这个错误,我不知道这意味着什么:

I am getting this error and I am not sure what it means:

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的最新版本。

I am using Netbeans and the latest version of Apache POI that was released May 11, 2015.

行23错误指的便是这一行:

The line 23 that the error refers to is this line:

XSSFWorkbook workbook = new XSSFWorkbook(file);

我在做什么错了?

What am I doing wrong?

推荐答案

您缺少的xmlbeans罐(甚至更多)

You are missing the xmlbeans jar (and possibly more)

的Apache POI拥有描述所有的组件和它们的依赖,还是得心应手页如果你使用Maven这一切都为你照顾

Apache POI has a handy page describing all of the components and their dependencies, or if you use Maven it's all taken care of for you

在一个二进制版本,你会发现在 OOXML-LIB 子目录的XMLBeans。补充一点,和其他任何广口瓶需要你使用到类路径中的组件

In a binary release, you'll find xmlbeans in the ooxml-lib subdirectory. Add that, and any other jars needed for the components you're using to your classpath

这篇关于Java程序使用Apache POI让我奇怪的例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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