我正在尝试解析此xml提要
http://www.billboard.com/rss/charts/hot-100
但每当我尝试阅读描述标签时,它都会抛出NullPointerException
。文档开头的标签是否是导致问题的标签?
我能够成功拉出所有其他字段。
这是我的代码:
Element element = result.getDocumentElement();
NodeList list = element.getElementsByTagName("item");
try{
if(list != null && list.getLength()>0){
for(int i=0;i<list.getLength();i++){
Element entry = (Element)list.item(i);
Element title = (Element)entry.getElementsByTagName("title").item(0);
String strTitle = title.getFirstChild().getNodeValue();
Log.i("Zealdeveloper", "Title");
Element link = (Element)entry.getElementsByTagName("link").item(0);
String strLink = link.getFirstChild().getNodeValue();
Log.i("Zealdeveloper", "Link");
Element pubdate = (Element)entry.getElementsByTagName("pubDate").item(0);
String strPubdate = pubdate.getFirstChild().getNodeValue();
Log.i("Zealdeveloper", "pubdate");
Element description = (Element)entry.getElementsByTagName("description").item(0);
String strDescription = description.getFirstChild().getNodeValue();
Log.i("Zealdeveloper", "Description"); } }
我得到的例外:
12-06 13:44:09.202: I/Zealdeveloper(824): Title
12-06 13:44:09.202: I/Zealdeveloper(824): Link
12-06 13:44:09.202: I/Zealdeveloper(824): pubdate
12-06 13:44:09.202: W/System.err(824): java.lang.NullPointerException
12-06 13:44:09.202: W/System.err(824): at com.zealdeveloper.musicfreak.MusicFreakActivity$ParseXmlFeeds.onPostExecute(MusicFreakActivity.java:152)
12-06 13:44:09.212: W/System.err(824): at com.zealdeveloper.musicfreak.MusicFreakActivity$ParseXmlFeeds.onPostExecute(MusicFreakActivity.java:1)
12-06 13:44:09.212: W/System.err(824): at android.os.AsyncTask.finish(AsyncTask.java:417)
12-06 13:44:09.212: W/System.err(824): at android.os.AsyncTask.access$300(AsyncTask.java:127)
12-06 13:44:09.212: W/System.err(824): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
12-06 13:44:09.212: W/System.err(824): at android.os.Handler.dispatchMessage(Handler.java:99)
12-06 13:44:09.212: W/System.err(824): at android.os.Looper.loop(Looper.java:123)
12-06 13:44:09.212: W/System.err(824): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-06 13:44:09.212: W/System.err(824): at java.lang.reflect.Method.invokeNative(Native Method)
12-06 13:44:09.212: W/System.err(824): at java.lang.reflect.Method.invoke(Method.java:521)
12-06 13:44:09.212: W/System.err(824): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-06 13:44:09.222: W/System.err(824): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-06 13:44:09.222: W/System.err(824): at dalvik.system.NativeStart.main(Native Method)
谢谢!
答案 0 :(得分:0)
是否有像“&amp;”这样的角色或XML文件中的“ - ”?! 我弄清楚解析器无法解析那些! 如果你有一个
,只是尝试改变它