未找到Android Studio DatatypeFactoryImpl

问题描述 投票:0回答:1

我尝试用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包添加到我的buildpath中,所以我不知道如何解决这个问题。

java android xml xerces
1个回答
1
投票

如果你是一个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

Maven的:

<!-- 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'
© www.soinside.com 2019 - 2024. All rights reserved.