“未找到提供程序 com.bea.xml.stream.EventFactory"加载 XLSX 文件时 [英] "Provider com.bea.xml.stream.EventFactory not found" when loading XLSX file
问题描述
我已经在 Java 桌面应用上成功使用了 Apache POI,并希望在 Android 上使用它来阅读和使用编写 Excel 文件.
I've used Apache POI successfully on Java desktop app, and would like to use it on Android for reading & writing Excel files.
这是我的 Github 仓库:https://github.com/anta40/StockChecker
Here's my Github repo: https://github.com/anta40/StockChecker
每次我尝试打开一个 XLSX 文件时,最终应用程序都会因为
Everytime I try to open an XLSX file, eventually the app crashes because of
org.apache.poi.javax.xml.stream.FactoryConfigurationError: Providercom.bea.xml.stream.EventFactory 未找到
org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
这是我的 build.gradle 的内容:应用插件:'com.android.application'
Here's the content of my build.gradle: apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.anta40.app.stockchecker"
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.SUPERCILEX.poi-android:poi:3.17'
implementation 'com.github.angads25:filepicker:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
如何解决这个问题?
在 build.gradle 上添加这一行:
Adding this line on build.gradle:
实现'com.fasterxml:aalto-xml:1.1.0'
implementation 'com.fasterxml:aalto-xml:1.1.0'
不起作用.您会收到很多这样的错误消息:
doesn't work. You'll get lots of error messages like these:
重复类org.codehaus.stax2.ri.typed.ValueDecoderFactory$IntDecoder 在模块 poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) 和stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) 重复类 org.codehaus.stax2.ri.typed.ValueDecoderFactory$IntegerDecoder在模块 poi-3.17.jar 中找到(com.github.SUPERCILEX.poi-android:poi:3.17) 和 stax2-api-4.1.jar(org.codehaus.woodstox:stax2-api:4.1) 重复类org.codehaus.stax2.ri.typed.ValueDecoderFactory$LongArrayDecoder 找到在模块 poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17)和 stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) 重复类 org.codehaus.stax2.ri.typed.ValueDecoderFactory$LongDecoder在模块 poi-3.17.jar 中找到(com.github.SUPERCILEX.poi-android:poi:3.17) 和 stax2-api-4.1.jar(org.codehaus.woodstox:stax2-api:4.1) 重复类org.codehaus.stax2.ri.typed.ValueDecoderFactory$QNameDecoder 在模块 poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) 和stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) 重复在模块中找到类 org.codehaus.stax2.ri.typed.ValueEncoderFactorypoi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) 和stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1)
Duplicate class org.codehaus.stax2.ri.typed.ValueDecoderFactory$IntDecoder found in modules poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) and stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) Duplicate class org.codehaus.stax2.ri.typed.ValueDecoderFactory$IntegerDecoder found in modules poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) and stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) Duplicate class org.codehaus.stax2.ri.typed.ValueDecoderFactory$LongArrayDecoder found in modules poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) and stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) Duplicate class org.codehaus.stax2.ri.typed.ValueDecoderFactory$LongDecoder found in modules poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) and stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) Duplicate class org.codehaus.stax2.ri.typed.ValueDecoderFactory$QNameDecoder found in modules poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) and stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) Duplicate class org.codehaus.stax2.ri.typed.ValueEncoderFactory found in modules poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) and stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1)
推荐答案
在你的依赖中排除这个 stax2-api-4.1.jar 并重建项目
exculde this stax2-api-4.1.jar in your dependency and rebuild the project
编辑 1- 我知道我的编辑有点晚了,但刚刚解决了它,只需将您的 System.properties 移动到您初始化应用程序的静态块中.这将解决您的问题.
Edit 1- I know i am a bit late with the edit, but solved it just now, just move your System.properties in a static block where you initialize your app. This will solve your problem.
public class YourActivity extends AppCompatActivity {
//scope......
static {
System.setProperty(
"org.apache.poi.javax.xml.stream.XMLInputFactory",
"com.fasterxml.aalto.stax.InputFactoryImpl"
);
System.setProperty(
"org.apache.poi.javax.xml.stream.XMLOutputFactory",
"com.fasterxml.aalto.stax.OutputFactoryImpl"
);
System.setProperty(
"org.apache.poi.javax.xml.stream.XMLEventFactory",
"com.fasterxml.aalto.stax.EventFactoryImpl"
);
}
这篇关于“未找到提供程序 com.bea.xml.stream.EventFactory"加载 XLSX 文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!