简体   繁体   中英

Android Studio DatatypeFactoryImpl not found

I try to generate an XML file with android studio and i get this error:

 Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found.

The problem come from the "JAXBContext" line. I have a fonction which make XML file its code is

        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();
    }

On android studio i add the xerces package to my buildpath, so i don't know how to resolve this.

If you are an Android Developer, as the document said Note that you must supply your own implementation (such as Xerces); Android does not ship with a default implementation. 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

So, try adding dependency 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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM