我正在尝试使用BeanIO读取/写入Android应用程序中的csv文件。当我尝试创建StreamFactory
的实例时,我收到以下错误:
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
发生这种情况的代码如下所示:
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);
}
我是Android和BeanIO开发的新手,所以如果我错过了一些明显的东西,我会道歉。我已经做了相当多的谷歌搜索,找不到任何有类似问题的人。 BeanIO甚至与Android兼容吗?我应该在某处指定不同的DocumentBuilderFactory
实现吗?
非常感谢您解决此错误的任何帮助!
答案 0 :(得分:1)
我觉得回答这个问题有点迟了,但几周前我不得不对这个问题感到满意。这是我的评估和解决方案:
首先,如果您查看日志:
03-02 08:52:19.076:E / AndroidRuntime(9305):引起: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更多
主要问题发生在DocumentBuilderFactoryImpl。
解决方法是在beanIO项目中使用库 xerces-for-android ,这是一个与DocumentBuilderFactoryImpl等效的库。
github中的图书馆:https://github.com/MaTriXy/xerces-for-android
github中的图书馆:https://github.com/dthommes/droid-java-beans
在BeanIO项目中添加两个库之后,必须生成jar文件。
如果你不想做那个累了的工作,我只是将这些罐放在我的驱动器谷歌帐户中
https://drive.google.com/open?id=1P3HPUopjFiAk31qcks_vrDijEPsAkGzQ
PS:我必须将这3个罐子放在我的 Android项目
中最好的问候。