如何在Android Studio中使用javax.xml.transform.stax? [英] How to use javax.xml.transform.stax in Android Studio?

查看:150
本文介绍了如何在Android Studio中使用javax.xml.transform.stax?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android Studio中遇到了一个奇怪的问题.我也在使用最新的JDK.我似乎无法导入以下内容:

I'm running into a strange problem in Android Studio. I'm also using latest JDK. I can't seem to import the following :

  • javax.xml.stream
  • javax.xml.transform.stax

它们都不可用,我也不知道为什么.在一个非android项目中,我可以导入这些.有什么线索为什么这些在Android中会丢失?

They both are unavailable and I don't know why. In a non android project I'm able to import these. Any clue why these are missing in android?

如果没有,简单的解决方案是我从maven添加了这些依赖项.但是运行后出现此错误:

If not, the simple solution is that I added these dependencies from maven. But after running I'm getting this error:

在未构建核心库时对核心类(java.*或javax.*)的不当使用或错误使用.

推荐答案

Android使用的Java JDK与用于台式机或服务器应用程序的Java JDK不同;它使用自己的JDK实现,该实现添加了android.*层次结构,但省略了标准JDK中的某些软件包,尤其是javax.* Java扩展中的软件包.对于您来说不幸的是,javax.xml.streamjavax.xml.transform.stax是他们未选择实现的内容.此外,出于安全原因,Android运行时不允许您从外部JAR文件加载任何java.*javax.*类. 此答案可以更好地描述这种情况.

Android doesn't use the same Java JDK as what you use for a desktop or server app; it uses its own implementation of the JDK, which adds the android.* hierarchy but leaves out some packages that are in the standard JDK, especially in the javax.* Java extensions. Unfortunately for you, javax.xml.stream and javax.xml.transform.stax are among the things they didn't choose to implement. Moreover, the Android runtime won't allow you to load any java.* or javax.* classes from an external JAR file for security reasons**. This answer may describe the situation a little better.

您最好的选择可能是:1)使用专门为Android构建的其他第三方库,例如 SimpleXML ; 2)寻找库的重新打包版本,例如 JAXB的努力;或3)使用 Jar Jar链接之类的工具来为您重新包装.

Your best bets are probably: 1) use a different third-party library specifically built for Android, such as SimpleXML; 2) look for a repackaged version of the libraries, like this JAXB effort; or 3) use a tool like Jar Jar Links to do the repackaging for you.

也请参见这份出色的指南关于在Android中解析JSON和XML.

Also see this excellent guide on parsing JSON and XML in Android.

**注意:我找不到Google提供的任何文件来证实这一点;这只是通常重复的事实".如果任何人都可以指出有关Android处理第三方java[x].*类的权威性声明,请使用链接发表评论,或编辑此答案.

** Note: I can't find any documentation from Google to substantiate this; it's just a commonly repeated "fact". If anyone can point to an authoritative statement about Android's handling of third-party java[x].* classes, please comment with a link, or edit this answer.

这篇关于如何在Android Studio中使用javax.xml.transform.stax?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆