Java Apache POI 错误加载 XSSFWorkbook 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39670382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache POI error loading XSSFWorkbook class
提问by Cameron Zach
I'm trying to write a program that works with Excel docs, but the HSSF format is too small for my requirements. I'm attempting to move to XSSF, but I keep getting errors when trying to use it.
我正在尝试编写一个适用于 Excel 文档的程序,但 HSSF 格式对于我的要求来说太小了。我正在尝试转向 XSSF,但在尝试使用它时我不断收到错误消息。
I managed to solve the first two by adding xmlbeans-2.3.0.jar and dom4j-1.6.jar to my program, but now this error is coming up, which doesn't seem to be resolved by adding the Apache commons jar available on the Apache website.
我设法通过将 xmlbeans-2.3.0.jar 和 dom4j-1.6.jar 添加到我的程序中来解决前两个问题,但是现在出现了这个错误,这似乎无法通过添加 Apache commons jar 来解决阿帕奇网站。
The error is as follows:
错误如下:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
at hot.memes.ExcelCreator.main(ExcelCreator.java:66)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
回答by Lakhwinder Sharma
Add commons-collections4-x.x.jar file in your build path and try it again. It will work.
在您的构建路径中添加 commons-collections4-xxjar 文件并重试。它会起作用。
You can download it from https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.0
您可以从https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.0下载
回答by Bharath Nadukatla
Hurrah! Adding commons-collections jar files to my project resolved this problem. Two thumbs up to Lucky Sharma.
欢呼!将 commons-collections jar 文件添加到我的项目中解决了这个问题。向 Lucky Sharma 竖起两个大拇指。
Solution: Add commons-collections4-4.1.jar file in your build path and try it again. It will work.
解决方案:在您的构建路径中添加 commons-collections4-4.1.jar 文件,然后再试一次。它会起作用。
You can download it from https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.1
您可以从https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.1下载
回答by Anshu kumar
commons-collections4-x.x.jar definitely solve this problem but Apache has removed the Interface ListValuedMap from commons-Collections4-4.0.jar so use updated version 4.1 it has the required classes and Interfaces.
commons-collections4-xxjar 确实解决了这个问题,但是 Apache 已经从 commons-Collections4-4.0.jar 中删除了接口 ListValuedMap,所以使用更新的 4.1 版本,它具有所需的类和接口。
Refer here if you want to read Excel (2003 or 2007+) using java code.
如果您想使用 Java 代码阅读 Excel(2003 或 2007+),请参阅此处。
http://www.codejava.net/coding/how-to-read-excel-files-in-java-using-apache-poi
http://www.codejava.net/coding/how-to-read-excel-files-in-java-using-apache-poi
回答by HopeKing
Please note that 4.0 is not sufficient since ListValuedMap, was introduced in version 4.1.
请注意,4.0 还不够,因为 ListValuedMap 是在 4.1 版中引入的。
You need to use this maven repository linkfor version 4.1. Replicated below for convenience
您需要使用此4.1 版的Maven 存储库链接。为方便起见复制如下
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
回答by Swetha
Yeah, resolved the exception by adding commons-collections4-4.1 jar file to the CLASSPATH user varible of system. Downloaded from https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.1
是的,通过将 commons-collections4-4.1 jar 文件添加到系统的 CLASSPATH 用户变量来解决异常。从https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.1下载
回答by Mostafiz
If you have downloaded pio-3.17 On eclipse: right click on the project folder -> build path -> configure build path -> libraries -> add external jars -> add all the commons jar file from the "lib". It's worked for me.
如果您已下载 pio-3.17 在 eclipse 上:右键单击项目文件夹 -> 构建路径 -> 配置构建路径 -> 库 -> 添加外部 jar -> 从“lib”添加所有公共 jar 文件。它对我有用。