且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 android 上使用 com.bea.xml.stream 包

更新时间:2023-01-19 20:36:50

检查 FAQ #18:

这个错误表明类 XMLEventFactory 没有提供POI 所依赖的功能.可以有多个不同的原因:

This error indicates that the class XMLEventFactory does not provide functionality which POI is depending upon. There can be a number of different reasons for this:

过时的 xml-apis.jar、stax-apis.jar 或 xercesImpl.jar:

Outdated xml-apis.jar, stax-apis.jar or xercesImpl.jar:

  • Java 5 及更低版本需要这些库,但符合规范的 Java 6 实现实际上不需要这些库,因此请尝试从您的类路径中删除这些库.如果这是不可能的,尝试升级到这些 jar 文件的更新版本.

...

您可能需要通过您使用的构建系统排除 stax:stax-api 依赖项.我刚刚通过应用这种方法解决了一个类似的问题(相同的堆栈跟踪,但来自 Groovy).

You probably need to exclude the stax:stax-api dependency through the build system that you use. I just solved a similar problem (same stack trace but from Groovy) by applying this method.

更新:***使用 Maven 存储库中的依赖项,它将在很大程度上简化您的依赖项部分:

UPDATE: It is best if you use the dependencies from a Maven repository, it will largely simplify your dependencies section:

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:multidex:1.0.0'
    compile ('org.apache.poi:poi-ooxml:3.12') {
        exclude group: 'stax', module: 'stax-api'
    }
}

您现在还可以删除 libs 目录下的额外库.

You can now also remove the extra libraries that you have under the libs directory.

Apache POI 常见问题解答表明某些 Java 版本可能根本不需要 stax,尤其是 6 以上.

The Apache POI FAQ answer indicates that stax may not be needed at all for some Java versions, especially above 6.