1

I'm trying to use BeanIO to read/write to a csv file in an Android application. When I try to create an instance of the StreamFactory, I get the following error:

03-02 08:52:19.076: E/AndroidRuntime(9305): FATAL EXCEPTION: main
03-02 08:52:19.076: E/AndroidRuntime(9305): org.beanio.BeanIOException: Failed to load stream factory implementation class 'org.beanio.internal.DefaultStreamFactory'
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.StreamFactory.newInstance(StreamFactory.java:353)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.StreamFactory.newInstance(StreamFactory.java:304)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at com.catfoodcalc.io.CatFoodFileUtil.getBeanReader(CatFoodFileUtil.java:20)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at com.catfoodcalc.io.CatFoodFileUtil.retrieveSavedCatFoodList(CatFoodFileUtil.java:42)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at com.catfoodcalc.MainActivity.saveCatFood(MainActivity.java:176)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at com.catfoodcalc.MainActivity.access$0(MainActivity.java:164)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at com.catfoodcalc.MainActivity$1.onClick(MainActivity.java:194)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:174)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at android.os.Looper.loop(Looper.java:158)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at android.app.ActivityThread.main(ActivityThread.java:5789)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at java.lang.reflect.Method.invoke(Method.java:525)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at dalvik.system.NativeStart.main(Native Method)
03-02 08:52:19.076: E/AndroidRuntime(9305): Caused by: org.beanio.BeanIOException: Unable to validate using XSD: JAXP provider [org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl@41bc27f8] does not support XML Schema.
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.internal.config.xml.XmlMappingReader.createDocumentBuilderFactory(XmlMappingReader.java:125)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.internal.config.xml.XmlMappingReader.<init>(XmlMappingReader.java:50)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.internal.config.xml.XmlConfigurationLoader.<init>(XmlConfigurationLoader.java:34)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.internal.compiler.StreamCompiler.<init>(StreamCompiler.java:48)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.internal.DefaultStreamFactory.init(DefaultStreamFactory.java:48)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.StreamFactory.newInstance(StreamFactory.java:349)
03-02 08:52:19.076: E/AndroidRuntime(9305):     ... 15 more
03-02 08:52:19.076: E/AndroidRuntime(9305): Caused by: java.lang.IllegalArgumentException: http://java.sun.com/xml/jaxp/properties/schemaLanguage
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:86)
03-02 08:52:19.076: E/AndroidRuntime(9305):     at org.beanio.internal.config.xml.XmlMappingReader.createDocumentBuilderFactory(XmlMappingReader.java:119)
03-02 08:52:19.076: E/AndroidRuntime(9305):     ... 20 more

The code where this is happening looks like this:

    private static BeanReader getBeanReader() {
        StreamFactory factory = StreamFactory.newInstance();  //This is where the above exception is thrown
        factory.load(MAPPING_FILE);
        File inputFile = new File("myFile");
        return factory.createReader("myBeanIOStream", inputFile);
    }

I'm new to both Android and BeanIO development, so I apologize if I've missed something obvious here. I've done a fair amount of googling, and couldn't find anyone with a similar issue. Is BeanIO even compatible with Android? Should I be specifying a different DocumentBuilderFactory implementation somewhere?

Any help in resolving this error is greatly appreciated!

1 Answers1

1

I think it's kinda late for answer to this question, but I had to affort to this problem weeks ago. Here is my evaluation and solution:

  • At first, if you check your log:

    03-02 08:52:19.076: E/AndroidRuntime(9305): Caused by: java.lang.IllegalArgumentException: http://java.sun.com/xml/jaxp/properties/schemaLanguage 03-02 08:52:19.076: E/AndroidRuntime(9305): at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:86) 03-02 08:52:19.076: E/AndroidRuntime(9305): at org.beanio.internal.config.xml.XmlMappingReader.createDocumentBuilderFactory(XmlMappingReader.java:119) 03-02 08:52:19.076: E/AndroidRuntime(9305): ... 20 more

The main problem occurs in DocumentBuilderFactoryImpl.

The solution for this is using the library xerces-for-android , a library that have an equivalent for DocumentBuilderFactoryImpl, inside beanIO project.

Library in github: https://github.com/MaTriXy/xerces-for-android

  • But there you will have another problem inside beanIO. The class BeanUtils needs the class java.beans that is by default in java native. This time I used another library called droid-java-beans that have all classes from java.beans:

Library in github: https://github.com/dthommes/droid-java-beans

After adding twose libraries inside your BeanIO project, you have to generate the jar files.


If you don't want to do that tired job I've just put these jars inside my drive google account

https://drive.google.com/open?id=1P3HPUopjFiAk31qcks_vrDijEPsAkGzQ

PS: I had to put these 3 jars inside my Android project

Best regards.