本文介绍了“找不到提供者com.bea.xml.stream.EventFactory".加载XLSX文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在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

这是我的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:

不起作用.您会收到很多类似这样的错误消息:

doesn't work. You'll get lots of error messages like these:

推荐答案

将此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文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 08:57