我正在尝试在Android项目中使用Dozer。但是当我尝试将Bean映射到另一个Bean时,它会抛出以下错误:
06-16 09:45:56.687 1727-1727/ch.heia_fr.tic.ipal.test_dozer E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: ch.heia_fr.tic.ipal.test_dozer, PID: 1727
java.lang.RuntimeException: Unable to start activity ComponentInfo{ch.heia_fr.tic.ipal.test_dozer/ch.heia_fr.tic.ipal.test_dozer.MainActivity}: java.lang.IllegalArgumentException: http://apache.org/xml/features/validation/schema
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
Caused by: java.lang.IllegalArgumentException: http://apache.org/xml/features/validation/schema
at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:86)
at org.dozer.loader.xml.XMLParserFactory.createDocumentBuilderFactory(XMLParserFactory.java:56)
at org.dozer.loader.xml.XMLParserFactory.createParser(XMLParserFactory.java:35)
at org.dozer.loader.xml.MappingStreamReader.<init>(MappingStreamReader.java:43)
at org.dozer.loader.xml.MappingFileReader.<init>(MappingFileReader.java:44)
at org.dozer.DozerBeanMapper.loadFromFiles(DozerBeanMapper.java:219)
at org.dozer.DozerBeanMapper.loadCustomMappings(DozerBeanMapper.java:209)
at org.dozer.DozerBeanMapper.initMappings(DozerBeanMapper.java:315)
at org.dozer.DozerBeanMapper.getMappingProcessor(DozerBeanMapper.java:192)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:120)
at ch.heia_fr.tic.ipal.test_dozer.MainActivity.onCreate(MainActivity.java:26)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
这是我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "ch.heia_fr.tic.ipal.test_dozer"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions{
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'net.sf.dozer:dozer:5.4.0'
}
带来问题的代码:
PersonBean bean = new PersonBean();
bean.setFirstName("Bob");
bean.setLastName("Robert");
bean.setStreet("Main Street");
bean.setTown("Bern");
Mapper mapper = new DozerBeanMapper();
PersonDTO dto = mapper.map(bean, PersonDTO.class
我认为问题来自缺少的XML MappingFile,但我不知道将它放在android项目中的哪个位置。
由于
答案 0 :(得分:2)
它甚至没有开始搜索映射文件。如果你查看android-sdk-22中实现的DocumentBuilderFactory,你会发现该方法没有实现。它实际上抛出异常。
我想android中不支持xml bean映射定义。尝试使用文档中显示的API映射。
编辑:它看起来也不起作用。 Dozer仍尝试在地图调用中加载两个映射(构建器映射和基于文件的映射)。 很久以来,我尝试过Dozer,Orika和ModelMapper,但只有最后一个在android中运行。