[xmlpull]XmlPull常见错误

news/2024/6/19 7:01:21

[xmlpull]XmlPull常见错误

编写者

日期

关键词

郑昀@ultrapower

2005-9-28

Xmlpull kxml java

 

 

Xmlpull官方站点:http://www.xmlpull.org/

优点:不必等整个文档解析完成,部分求值结果早就可以开始反馈给用户。

What Is It?

XmlPull project is dedicated to be a site for

  • for general Pull parsing promotion/education (including StAX) and in particular to contain easy-to-reuse samples and code fragments

  • a resource for discussing new ideas and concepts related to pull parsing

  • a java namespace (org.xmlpull.*) and project location of a free implementation of the event object API and Factories, based on the StAX XMLStreamReade and old Common API for XML Pull Parsing

  • as java namespace and project location of StAX and XmlPull based utilities and samples such as:
    - providing an XML stream from a DOM tree
    - a DOM builder
    - SAX adapter
    - JUnit tests

  • as a maintenance resource for the existing XmlPull interface

XmlPullParserException:resource not found

网络中有很多人问到同样一个问题:

为什么我们在调用

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

时,总是得到这样的错误:

 

Exception in thread "main" org.xmlpull.v1.XmlPullParserException: caused by: org.xmlpull.v1.XmlPullParserException: resource not found: /META-INF/services/org.xmlpull.v1.XmlPullParserFactory make sure that parser implementing XmlPull API is available

    at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java:294)

虽然从http://www.xmlpull.org/v1/doc/api/org/xmlpull/v1/XmlPullParserFactory.html

看到了他们自己的注解:

 XmlPullParserFactory

If no name of parser factory was passed (or is null) it will try to find name by searching in CLASSPATH for META-INF/services/org.xmlpull.v1.XmlPullParserFactory resource that should contain a comma separated list of class names of factories or parsers to try (in order from left to the right). If none found, it will throw an exception.
NOTE:In J2SE or J2EE environments, you may want to use
newInstance(property, classLoaderCtx) where first argument is System.getProperty(XmlPullParserFactory.PROPERTY_NAME) and second is Thread.getContextClassLoader().getClass() .

看来它确实需要寻找这么一个资源:

META-INF/services/org.xmlpull.v1.XmlPullParserFactory

。但又没说如何才能找到它。

http://kxml.sourceforge.net/

下载的kxml2.jar加到你的项目中即可。这时候再调用

XmlPullParserFactory factory = XmlPullParserFactory.newInstance(

                            System.getProperty(XmlPullParserFactory.PROPERTY_NAME),

                   Thread.currentThread().getContextClassLoader().getClass() );

就通过了。

kxml2.jar就包含了META-INF/services/org.xmlpull.v1.XmlPullParserFactory,它的内容其实就是一句话:

org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer

 

 

 

 

编写者

日期

关键词

郑昀@ultrapower

2005-9-28

Xmlpull kxml java

 

 





http://www.niftyadmin.cn/n/3649611.html

相关文章

C#实战系列—学生信息管理系统(一)项目展示

最近在整理自己电脑上的学习资料,突然发现大二时小组一起做的C#项目——学生信息管理系统。就想运行起来玩玩。可是现在主机里面都是一些开发Android和Java的软件。visual studio 2010也早就卸载了。不过想到我们开发的这个系统在Windows 10系统上的兼容性不太好。所…

在VS Code中使用ESLint进行整理和格式化

介绍 (Introduction) When writing JavaScript with an editor such as Visual Studio Code, there are a number of ways you can ensure your code is syntactically correct and in line with current best practices. For example, it is possible to integrate a linter s…

C#实战系列—学生信息管理系统(二)源码分析

对部分核心源代码进行分析,项目已开源,查看完整代码,文章底部有链接。 学生信息管理系统分为三个部分 项目展示 源码分析 项目打包 现在展示的是对原有系统进行二次开发的结果。为2.0版本。 一、界面设计 1、新建项目 新建项目的时候选择Wi…

如何使用MongoDB和Docker设置Flask

The author selected the Internet Archive to receive a donation as part of the Write for DOnations program. 作者选择了Internet存档作为“ Write for DOnations”计划的一部分来接受捐赠。 介绍 (Introduction) Developing web applications can become complex and ti…

[p2p-jxta]myJXTA试用体验(1)

下载了jxta-myjxta-2.3.5.zip,解压缩后直接运行myjxta.bat,立马登录入JXTA网络,上面还真有几个对端呢。第一次用到这么直截了当的P2P Java程序。IBM上的JXTA资源:http://www-128.ibm.com/developerworks/cn/java/wi-jxta2/index.h…

[OTA]制作OTA短信来配置手机与服务器同步

[OTA]制作OTA短信来配置手机与服务器同步编写者日期关键词郑昀ultrapower 2005-9-26sms ota 同步 空中下载 手机 WDP WSP WBXML sync4j 同步设置本文档讲解了OTA的概念,给出了如何发送“同步设置”的OTA短信的步骤,并附带Java编写的源代码(http://www.cn…

C#实战系列—学生信息管理系统(三)项目打包

学生信息管理系统分为三个部分 项目展示 源码分析 项目打包 现在展示的是对原有系统进行二次开发的结果。为2.0版本。 一、项目打包过程 1、在项目的解决方案上右键,选择添加——新建项目 2、选择安装项目,名称随意。 3、项目新建以后,来到项…