gpt4 book ai didi

java - Android Studio DatatypeFactoryImpl 未找到

转载 作者:行者123 更新时间:2023-12-02 11:00:46 24 4
gpt4 key购买 nike

我尝试使用 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开发者,正如文档所说注意,你必须提供自己的实现(例如Xerces); Android 未附带默认实现。 https://developer.android.com/reference/javax/xml/datatype/DatatypeFactory.html#newInstance%28%29

因此,尝试添加依赖项xercesImpl

Maven:

<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
</dependency>

Gradle :

// https://mvnrepository.com/artifact/xerces/xercesImpl
compile group: 'xerces', name: 'xercesImpl', version: '2.12.0'

关于java - Android Studio DatatypeFactoryImpl 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51348471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com