[xmlpull]XmlPull常见错误
[xmlpull]XmlPull常見錯誤
| 編寫者<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> | 日期 | 關鍵詞 |
| 鄭昀@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. |
看來它確實需要尋找這么一個資源:
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 |
?
總結
以上是生活随笔為你收集整理的[xmlpull]XmlPull常见错误的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 北京地区的网络人口调查
- 下一篇: 人还是很需要成就感的