5

I really can't understand this one: it looks like Android has the XMLGregorianCalendar class, because it is documented here. But if you go ahead and try to use it, that's what you get:

10-27 17:21:43.677: E/AndroidRuntime(14850): Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found
10-27 17:21:43.677: E/AndroidRuntime(14850):    at javax.xml.datatype.DatatypeFactory.newInstance(DatatypeFactory.java:102)

This happens on the line:

DatatypeFactory datatype = DatatypeFactory.newInstance();

And guess what, it should not behave like this, as documented on the official Android Javadoc.

This looks like one of the not-so-smart things about Android. Why would you document something that can't be used? Does anyone have a solution on this, one that maybe does not include repackaging?

frapontillo
  • 10,499
  • 11
  • 43
  • 54

1 Answers1

9

It looks like even though it's been in the API since v8, no version of Android has ever shipped with an implementation. Handy, right?

One solution is to download the Xerces2 Java implementation jar and include it on your project's build path.

Your code would be only slightly different:

DatatypeFactory datatype = DatatypeFactoryImpl.newInstance();
Krylez
  • 17,414
  • 4
  • 32
  • 41
  • 1
    I've included xercesImpl.jar in my build path and copied to the lib directory but I am still getting error `Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found`. Is there anything else I should do to get it working? – Martin Nuc Apr 10 '13 at 12:02
  • You can try this link. It contains the datatype jar especially for android http://grepcode.com/file/repo1.maven.org/maven2/org.odftoolkit/odfdom-java/0.8.7/org/apache/xerces/jaxp/datatype/DatatypeFactoryImpl.java – Firnaz Sep 04 '15 at 05:25
  • @MartinNuc did you able to solve above problem you have mentioned above? I am facing the same problem can you please suggest me any solution. – Neha Sep 23 '16 at 07:27
  • @Neha sorry, I dont remember :( – Martin Nuc Sep 24 '16 at 08:37
  • @Neha @Martin You need to make sure you're using `DatatypeFactoryImpl.newInstance()` and not `DataTypeFactory.newInstance()` after including the .jar in your project. – Mavamaarten Jul 25 '18 at 07:43