Reputation: 21
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.
Upvotes: 2
Views: 3736
Reputation: 1169
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.
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'
Upvotes: 8