gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:57:23 25 4
gpt4 key购买 nike

我一直在尝试使上传(在旧的网络应用程序中)兼容 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包含在您的项目中,仅提供 Node 接口(interface)的实现(基于 xml-apis 1.0.b2 最新版本 1.1.3),并且不实现 getTextContent()根据Document Object Model (DOM) Level 3 Core Specification介绍的方法.

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

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

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

关于java - 如何修复通过apache POI上传xlsx文件时的AbstractMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55895427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com