java - 未找到 Android Studio DatatypeFactoryImpl
问题描述
我尝试使用 android studio 生成 XML 文件,但出现此错误:
Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found.
问题来自“JAXBContext”行。我有一个函数,它使 XML 文件的代码是
try {
File file = new File("D:\\Github\\Comedu\\file.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Resultat.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(this, file);
jaxbMarshaller.marshal(this, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
在 android studio 我将 xerces 包添加到我的构建路径中,所以我不知道如何解决这个问题。
解决方案
如果您是 Android 开发人员,如文档所述Note that you must supply your own implementation (such as Xerces); Android does not ship with a default implementation.
https://developer.android.com/reference/javax/xml/datatype/DatatypeFactory.html#newInstance%28%29
所以,尝试添加依赖xercesImpl
马文:
<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
</dependency>
摇篮:
// https://mvnrepository.com/artifact/xerces/xercesImpl
compile group: 'xerces', name: 'xercesImpl', version: '2.12.0'
推荐阅读
- tfs - TFS Visual Studio 2017:在源代码管理中按名称搜索文件
- c# - 如何在我的表格中从另一个班级画一条线?
- mysql - MySQL INSERT 使用 COUNT() 和 GROUP BY 错误`无效使用组函数`
- arrays - 如何访问闭包之外的数组?
- python - 每当使用 import cv2 时,OpenCV 都会出错
- scala - 如何在 spark scala 中删除换行符
- r - Flexdashboard checkboxGroupInput丢失ggplot数据
- java - setDisplayHomeAsUpEnabled 在我的一项活动中不起作用,但在其他任何地方都起作用
- jquery - jquery if ($("#notexist").length > 0) 抛出错误
- json - 如何从 URL 解析 Json 并在 Xcode 的 Collection View 中显示