找不到Android Studio DatatypeFactoryImpl

时间:2018-07-15 12:41:22

标签: java android xml xerces

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

1 个答案:

答案 0 :(得分:0)

如果您是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'