Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use XMLGregorianCalendar in Android, even if it is documented?

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?

like image 232
frapontillo Avatar asked Oct 27 '11 15:10

frapontillo


1 Answers

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();
like image 135
Krylez Avatar answered Oct 16 '22 04:10

Krylez