ant*_*a40 1 java excel android apache-poi
我已经在 Java 桌面应用程序上成功使用了 Apache POI,并希望在 Android 上使用它来读写 Excel 文件。
这是我的 Github 仓库:https : //github.com/anta40/StockChecker
每次我尝试打开 XLSX 文件时,最终应用程序都会因为
org.apache.poi.javax.xml.stream.FactoryConfigurationError:未找到提供程序 com.bea.xml.stream.EventFactory
这是我的 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'
}
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
在 build.gradle 上添加这一行:
实现 'com.fasterxml:aalto-xml:1.1.0'
不起作用。你会收到很多这样的错误信息:
在模块 poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) 和 stax2-api-4.1.jar (org.codehaus) 中发现重复类 org.codehaus.stax2.ri.typed.ValueDecoderFactory$IntDecoder .woodstox:stax2-api:4.1) 在模块 poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) 和 stax2- 中发现重复类 org.codehaus.stax2.ri.typed.ValueDecoderFactory$IntegerDecoder api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) 在模块 poi-3.17.jar (com.github.SUPERCILEX.poi-) 中发现重复类 org.codehaus.stax2.ri.typed.ValueDecoderFactory$LongArrayDecoder android:poi:3.17) 和 stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) 在模块 poi-3.17.jar 中发现重复类 org.codehaus.stax2.ri.typed.ValueDecoderFactory$LongDecoder (com.github.SUPERCILEX.poi-android:poi:3.17) 和 stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1) 在模块 poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi:3.17) 和 stax2-api 中发现的重复类 org.codehaus.stax2.ri.typed.ValueDecoderFactory$QNameDecoder -4.1.jar (org.codehaus.woodstox:stax2-api:4.1) 在模块 poi-3.17.jar (com.github.SUPERCILEX.poi-android:poi) 中发现重复类 org.codehaus.stax2.ri.typed.ValueEncoderFactory :3.17) 和 stax2-api-4.1.jar (org.codehaus.woodstox:stax2-api:4.1)codehaus.woodstox:stax2-api:4.1)codehaus.woodstox:stax2-api:4.1)
在您的依赖项中排除此 stax2-api-4.1.jar 并重建项目
编辑 1- 我知道我的编辑有点晚了,但刚刚解决了它,只需将您的 System.properties 移动到您初始化应用程序的静态块中。这将解决您的问题。
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"
);
}
Run Code Online (Sandbox Code Playgroud)
只需将这些依赖项包含在您的 build.gradle 模块中即可:
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '3.1.0'
implementation 'javax.xml.stream:stax-api:1.0'
implementation 'com.fasterxml:aalto-xml:1.2.2'
Run Code Online (Sandbox Code Playgroud)
不要使用最新版本的依赖项,因为它们会产生更多错误。
| 归档时间: |
|
| 查看次数: |
3364 次 |
| 最近记录: |