使用android、kotlin、apache poi在中读取xlsx文件时出错
使用kotlin、android、ApachePOI,我试图读取xlsx文件。 但以下错误发生在“WorkbookFactory.create(file)”行。 有人知道怎么修吗 现在它可以输出Excel文件,所以我想build.gradle设置是正确的 “错误” E/AndroidRuntime:致命异常:主 流程:com.example.jpwingsnikkeibpomikuji,PID:13735 java.lang.IllegalStateException:无法为android执行方法:onClick使用android、kotlin、apache poi在中读取xlsx文件时出错,android,excel,kotlin,apache-poi,Android,Excel,Kotlin,Apache Poi,使用kotlin、android、ApachePOI,我试图读取xlsx文件。 但以下错误发生在“WorkbookFactory.create(file)”行。 有人知道怎么修吗 现在它可以输出Excel文件,所以我想build.gradle设置是正确的 “错误” E/AndroidRuntime:致命异常:主 流程:com.example.jpwingsnikkeibpomikuji,PID:13735 java.lang.IllegalStateException:无法为android执行方
・・・・
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
・・・・
Caused by: java.lang.RuntimeException: http://xml.org/sax/properties/declaration-handler
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.<init>(Locale.java:3397)
at org.apache.xmlbeans.impl.store.Locale$XmlReaderSaxLoader.<init>(Locale.java:3087)
・・・・
Caused by: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/properties/declaration-handler
・・・・
可能还有一些数据是您需要发布的stacktrace。sax解析器出现了一些问题。您可以尝试将apache xerces 2.12.0添加到您的类路径中吗?这是通过以下方式解决的--我不确定XMLBeans 4.0.0是否可以与POI 4.1.2(使用XMLBeans 3.1.0构建)一起使用--但是您可以尝试将POI升级到5.0.0
・・・・
fun excelToroku(view: View){
verifyStoragePermissions(this)
val uploadPath: String = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()
val file = Paths.get(uploadPath + File.separator + "torokutest.xlsx").toFile()
Log.d("MyApp", file.exists().toString()) <--- true
val book:Workbook = WorkbookFactory.create(file) <--- here error occurs
・・・・
・・・・
dependencies {
implementation 'org.apache.poi:poi:4.1.2'
implementation "org.apache.poi:poi-ooxml:4.1.2"
implementation 'javax.xml.stream:stax-api:1.0'
・・・・