通过apache POI上传xlsx文件时如何修复AbstractMethodError

诺琳·拉索

我一直在尝试使上传(在旧的网络应用程序中)兼容 xls 和 xlsx 文件,xls 运行良好,但上传 xlsx 会引发此错误:

SEVERE: Servlet.service() for servlet [MainServlet] in context with path [/timesheet] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError: org.apache.crimson.tree.ElementNode2.getTextContent()Ljava/lang/String;
    at org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.readElement(PackagePropertiesUnmarshaller.java:146)
    at org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.loadCreated(PackagePropertiesUnmarshaller.java:162)
    at org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.unmarshall(PackagePropertiesUnmarshaller.java:124)
    at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:788)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:327)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:185)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:144)

当前的 poi lib 版本是 3.14,但我也尝试过 3.16(相同错误)和 3.17,该应用程序当前使用的是 Java 1.6

public List<AttendanceRecord> getAttendanceRecords(List<AttendanceRecordErrMsg> errorMessages) throws Exception {

        Workbook wb = WorkbookFactory.create(new FileInputStream(arFile)); //app already throws an error upon reaching this line

        List<AttendanceRecord> attendanceRecordList = new ArrayList<AttendanceRecord>();

萨马布德

出现这种错误的原因是因为你的项目中包含了Crimson Library,它只提供了接口上的实现(基于xml-apis 1.0.b2,最新版本1.1.3)Node,并没有实现getTextContent()根据Document引入的方法对象模型 (DOM) 级别 3 核心规范

要修复此类错误,您可以执行以下操作之一:

1.从您的项目中删除Crimson 库

2.通过添加以下行javax.xml.parsers.DocumentBuilderFactory指定系统属性以避免使用org.apache.crimson.jaxp.DocumentBuilderFactoryImpl
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

通过Apache POI读取大型Excel文件(xlsx)时出错

如何通过apache-httpclient上传文件?

如何用Apache POI读取.xlsx文件?

如何通过Apache poi设置Word文件的全局字体?

如何通过Apache Poi添加评论

Apache POI生成的xlsx文件大小大于通过Microsoft Excel手动创建的文件大小

通过与Java结合使用Apache POI创建excel(.xlsx)文件后,文件已损坏

如何使用Apache POI加载大型xlsx文件?

使用Apache POI通过流/分页策略将xlsx文件解析为大块

如何通过Apache POI在XLSX中写入非常大的数字

通过apache poi读取excel文件(在classpath中)

如何修复使用Apache Commons VFS将文件上传到SFTP服务器时发生的错误

读取xlsx文件行时的Apache POI ClassCastException

尝试通过 c# 从 html 访问上传的文件时,如何修复 Visual Studio 中的 NullReference 错误?

通过php在服务器apache上上传文件

如何通过Apache POI在Excel中设置字体颜色RGB

如何从Apache HttpClient 4.x通过HttpPut上传InputStream

任务运行两次时,Apache POI将数据附加到xlsx文件

如何让Apache通过VirtualBox服务网站?

如何通过Apache执行pcntl函数

如何通过Apache Airflow运行Shell脚本

如何使用Java Apache POI从xlsx文件的特定单元格获取值

如何使用Java Apache POI库从XLSX文件中的特定单元格获取值

使用Apache POI时如何修复Android Studio中的Java编译器错误

通过Nginx提供静态文件时如何修复404错误

如何修复通过 PHP 下载时损坏的 PDF 文件

如何通过Java代码更改Apache flume的配置文件?

无法通过多个for循环写入Excel行列(apache poi)

通过XSSFRichTexString和Jsoup的Apache POI Excel文本格式