[Htmlparser-user] NullPointer Exception: NodeList.add method, htmlparser 1_5
Brought to you by:
derrickoswald
|
From: Riaz u. <ru...@ya...> - 2006-03-15 17:26:03
|
Hi,
I have attached the procedure below, now when I call this procedure it returns a null pointer excetion in the add method. It was working fine when I had it in the main function, but it does not run when I created this procedure, I think I need some java help on this, can someone suggest what I can do?
public static NodeList extractLinkFromSpanTag(String url) throws ParserException
{
int i =0;
NodeList nodelistOfLinks = null;
Parser parser = new Parser(url);
// Step 2. Collecting Tags in a list.
NodeList list = parser.parse (null);
//news links are at the span tag (time), spanList stores the span tags
// Step 3. Keep only the SPAN tags in spanList.
NodeList listOfSpanTags = list.extractAllNodesThatMatch(new TagNameFilter ("SPAN"),true);
while(i < listOfSpanTags.size())
{ // Beginning While loop to extract links
Span spanTag = (Span)listOfSpanTags.elementAt(i);
// System.out.println(listOfSpanTags.size());
// We only need SPAN tags with attribute "class = 'recenttimedate'"
// Move to the link in the span tag
if(spanTag.getText().equals("span class=recenttimedate"))
nodelistOfLinks.add(listOfSpanTags.elementAt(i).getParent());
i++;
}// End of while loop to extract links
while(i < nodelistOfLinks.size())
{
System.out.println(nodelistOfLinks.elementAt(i));
i++;
}
return nodelistOfLinks;
}
---------------------------------
Yahoo! Mail
Bring photos to life! New PhotoMail makes sharing a breeze. |