Skip to content

XMLParser problem when using poi-on-android and SODS at the same time #39

@Moonglasses

Description

@Moonglasses

Hi there,
I was recently looking for a solution that'd help me with processing spreadsheet files, which wasn't an easy task.
For processing xls/xlsx files I settled wtih using a "poi-on-android" library, which puts together all the pieces and libraries necessary to "just work".
Now when I try to use SODS as a complementary library to parse ODS files, I run into couple of problems:

Running SODS completely standalone throws following error:
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/stream/XMLInputFactory;
Which I'm able to solve like so and SODS is running just fine then:
implementation group: 'stax', name: 'stax', version: '1.2.0'

Running SODS side by side with poi-on-android without previous import throws the exact same error.

Running SODS side by side with poi-on-android, which is what I'd like to achieve, with the inclusion of stax library throws following error:
Process: com.moonglasses.odsimporttest, PID: 31140 java.lang.ExceptionInInitializerError at com.github.miachm.sods.OdsReader.<init>(OdsReader.java:19) at com.github.miachm.sods.OdsReader.load(OdsReader.java:37) at com.github.miachm.sods.SpreadSheet.<init>(SpreadSheet.java:52) at com.moonglasses.odsimporttest.ODSReader.read(ODSReader.java:35) at com.moonglasses.odsimporttest.MainActivity.lambda$initActivityLauncher$1$com-moonglasses-odsimporttest-MainActivity(MainActivity.java:65) at com.moonglasses.odsimporttest.MainActivity$$ExternalSyntheticLambda1.run(Unknown Source:6) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923) Caused by: java.lang.ClassCastException: com.fasterxml.aalto.stax.InputFactoryImpl cannot be cast to javax.xml.stream.XMLInputFactory at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136) at com.github.miachm.sods.XmlReaderEventImpl.<clinit>(XmlReaderEventImpl.java:10) at com.github.miachm.sods.OdsReader.<init>(OdsReader.java:19)  at com.github.miachm.sods.OdsReader.load(OdsReader.java:37)  at com.github.miachm.sods.SpreadSheet.<init>(SpreadSheet.java:52)  at com.moonglasses.odsimporttest.ODSReader.read(ODSReader.java:35)  at com.moonglasses.odsimporttest.MainActivity.lambda$initActivityLauncher$1$com-moonglasses-odsimporttest-MainActivity(MainActivity.java:65)  at com.moonglasses.odsimporttest.MainActivity$$ExternalSyntheticLambda1.run(Unknown Source:6)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:923) 

The poi-on-android library itself requires a certain hack to make it find a suitable XML Parser, the recomedation is to use following code:
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");

Using or not using this doesn't change the way SODS behaves. I was guessing I could maybe use this hack separately for poi and for SODS to convince both to use the XML Parser of their liking before I use them, but I'm just lost in all the stuff surrounding the topic of processing spreadsheet files on android in general.

Would someone more knowledgeable in the topic be so kind to maybe suggest some solutions please?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions