[alibaba/easyexcel]org.xml.sax.SAXNotRecognizedException 能帮我看看这是什么原因导致的吗?折腾了3天了,再不行弃坑了

2024-05-11 901 views
3

异常代码 1.MainActivity.java核心代码截图: image 上述的path测试过,没有问题.demo.xlsx是存在手机上的测试文件,内容与easyexcel库中的demo.xlsx一致. 2.上述的DemoData和DemoDataListener也是与库demo中内容一致.

报错内容 image

项目依赖 image

回答

3

遇到同样的问题,原因是http://apache.org/xml/features/disallow-doctype-decl 这个链接404了,这个feature是用来设置禁用DTD的,即不允许将外部实体包含在传入的 XML 文档中,从而防止XML实体注入。 image

但是,很遗憾,我也不知道该怎么fix ?

1

Android端要跑起来真难啊

7

我也有遇到这个问题。 java环境1.8 报错:

org.xml.sax.SAXNotRecognizedException: Feature 'http://javax.xml.XMLConstants/feature/secure-processing' is not recognized.

推测是xml解析器加载错了。具体未深究 增加依赖(gradle):

compile group: 'xerces', name: 'xercesImpl', version: '2.11.0'

参考链接: https://www.jianshu.com/p/70427180eaf0

6

有人解决吗?

7

我也遇到了这个问题,解决不了打算用POI试试,在群里请教了一下大佬说POI也有坑,因为Java和安卓的一个基础类实现方式不一样。

1

大佬,我也遇到一样的了,之前跑着没问题,今天一看报这个错了

1

解决了吗

3

@lichuanjun @gotoorder @AlexJialene @VamChao @zhuangjiaju

克隆了一份代码,将这个feature异常包了起来

           try {
                saxFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            } catch (SAXNotRecognizedException e) {
                log.warn(
                    "SAXNotRecognizedException occur, not supported feature: " +
                        "http://apache.org/xml/features/disallow-doctype-decl, which will disable DOCTYPE declaration" +
                        " if set true.");
            }

在Android项目里以jar包形式引入自己编译的easyexcel包,在gradle文件里面引入以下依赖:

implementation 'org.apache.poi:poi:4.1.2'
implementation 'org.apache.poi:poi-ooxml:4.1.2'
implementation 'org.apache.poi:poi-ooxml-schemas:4.1.2'
implementation 'org.apache.commons:commons-csv:1.8'
implementation 'cglib:cglib:3.3.0'
implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'org.ehcache:ehcache:3.8.1'
implementation 'javax.xml.stream:stax-api:1.0'

以上在 compileSdk 31 minSdk 26 targetSdk 31 条件下测试可用,其他没有测试过。

上面代码的fork地址:https://github.com/xworks/easyexcel

1

该问题已经在3.1.0+版本里面解决,最新版本:Maven central

2

@lichuanjun @gotoorder @AlexJialene @VamChao @zhuangjiaju

克隆了一份代码,将这个feature异常包了起来

           try {
                saxFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            } catch (SAXNotRecognizedException e) {
                log.warn(
                    "SAXNotRecognizedException occur, not supported feature: " +
                        "http://apache.org/xml/features/disallow-doctype-decl, which will disable DOCTYPE declaration" +
                        " if set true.");
            }

在Android项目里以jar包形式引入自己编译的easyexcel包,在gradle文件里面引入以下依赖:

implementation 'org.apache.poi:poi:4.1.2'
implementation 'org.apache.poi:poi-ooxml:4.1.2'
implementation 'org.apache.poi:poi-ooxml-schemas:4.1.2'
implementation 'org.apache.commons:commons-csv:1.8'
implementation 'cglib:cglib:3.3.0'
implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'org.ehcache:ehcache:3.8.1'
implementation 'javax.xml.stream:stax-api:1.0'

以上在 compileSdk 31 minSdk 26 targetSdk 31 条件下测试可用,其他没有测试过。

上面代码的fork地址:https://github.com/xworks/easyexcel

大佬,为啥你把你的代码拷下来还是用不了呢,报com.alibaba.excel.exception.ExcelGenerateException: java.lang.ExceptionInInitializerError这个错

7

大佬,确实有效 跑着没问题吗?