-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XMLParser problem when using poi-on-android and SODS at the same time #39
Comments
Thanks for your report! Please ensure you have provided enough info in order to recreate the issue, including the problematic ODS File.' first issue |
This look really interesting. SODS wasn't designed to run in Android but I suppose it could work. The problem is to find a suitable XML parser which replaces javax. Do you have a XML parser in Android which API is similar to the javax.xml.stream? |
It actually does work just fine if I use it alone without the poi and resolve the XML parser error by importing the stax library which I mentioned: The problem is, my priority is parsing xls files, therefore I need to have the xls processing working. And after a day of work only working solution on Android I found was the poi-on-android library, which does some voodoo to make the XML parser work, because it runs into the same problems if you want to use just the apache poi libraries. I'm not a super skilled developer, but even all the smart ppl had a hard time making these work on Android. But back to the issue, I think the stax library should be more than suitable if it works alone, it does contain a XML parser. But I can't figure out why poi library suddenly interferes with this even if I don't set the system properties and therefore not making it look in the wrong places for the parser. |
Probably you could fork SODS and change the code in order to use stax instead of javax. Since the XML API is the same, you only need to change the import name and it should just work. |
Sounds reasonable, gonna give it a try perhaps later tomorrow and get back here with the result. Thank you for you time so far. |
Hi Miguel, I managed to make your code work in my project, but with a big questionmark in the air. After some time of trying I realized I really lack the knowledge and mostly time right now to figure out how to compile the possible changes I'd make to your project and use this new lib in my project, so I went the easy way just to try if I can even make it work. Maybe I can use the forked project as a module in the project of mine side by side, but again, that's out of my knowledge scope and I'm close to few deadlines. |
Thanks for heading back! It's a shame Java is not entirely compatible with Android. Thanks for trying and sharing the experience. Even though Android is not a supported platform for SODS. I could try to add a feature in the API which allows to set a custom XML parser, something like:
Maybe this could allow a way to work in Android. It's worth to study. |
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?
The text was updated successfully, but these errors were encountered: