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

こ雲淡風輕ζ 提交于 2019-11-30 05:36:22

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/7918466/cant-use-xmlgregoriancalendar-in-android-even-if-it-is-documented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!