I have written the code for parsing image url from <image>
tag.
The code is below:
NodeList imageLink = docElement.getElementsByTagName("image");
String nUrl;
if (imageLink.toString() != null) {
Element element = (Element) imageLink.item(0);
NodeList imageUrl = element.getElementsByTagName("url");
if (imageUrl.toString() != null) {
Element imageFirst = (Element) imageUrl.item(0);
nUrl = imageFirst.getFirstChild().getNodeValue();
Log.d(TAG,
"<<<<<<<<<<<<<<<<<<<<<<..............Image Url is : "
+ nUrl
+ ".....................>>>>>>>>>>>>>>>>>.....");
} else {
Log.d(TAG,
"<<<<<<<<<<<<<<<<<<<<<<..............Image Url is null : .....................>>>>>>>>>>>>>>>>>.....");
nUrl = "http://static.dnaindia.com/images/710/logo_dna_rss.gif";
}
} else {
Log.d(TAG,
"<<<<<<<<<<<<<<<<<<<<<<..............Image tag is not found.....................>>>>>>>>>>>>>>>>>.....");
nUrl = "http://static.dnaindia.com/images/710/logo_dna_rss.gif";
}
It was working fine with the rss feed which having <image> tag
. I want to set default image for the Rss which does not having <image>
url.
But my code showing java.lang.NullPointerException
in this line NodeList imageUrl = element.getElementsByTagName("url");
.
How to check null for NodeList
?
And give me any idea to rectify it.
Thank you in advance!!!