Re: [Htmlparser-user] NullPointer Exception: NodeList.add method, htmlparser 1_5
Brought to you by:
derrickoswald
|
From: Ian M. <ian...@gm...> - 2006-03-17 10:13:49
|
Looks to me like nodelistOfLinks is null. First of all you have this
line of code:
NodeList nodelistOfLinks =3D null;
Then the next line of code that mentions the nodelistOfLinks object is:
nodelistOfLinks.add(listOfSpanTags.elementAt(i).getParent());
So you're trying to use a method on a null object. Instead of:
NodeList nodelistOfLinks =3D null;
You probably want:
NodeList nodelistOfLinks =3D new NodeList();
Ian
On 3/16/06, Riaz uddin <ru...@ya...> wrote:
> The error is occuring at this statement:
>
> nodelistOfLinks.add(listOfSpanTags.elementAt(i).getParent());
>
>
> Ian Macfarlane <ian...@gm...> wrote:
>
> The stack trace will tell you which line the NullPointerException was
> thrown on. Why don't you tell us which line it's occuring on? That
> will help pin it down.
>
> Ian
>
> On 3/15/06, Riaz uddin wrote:
> > 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 w=
hat
> I
> > can do?
> >
> > public static NodeList extractLinkFromSpanTag(String url) throws
> > ParserException
> > {
> > int i =3D0;
> >
> > NodeList nodelistOfLinks =3D null;
> > Parser parser =3D new Parser(url);
> > // Step 2. Collecting Tags in a list.
> > NodeList list =3D 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 =3D list.extractAllNodesThatMatch(new
> > TagNameFilter ("SPAN"),true);
> >
> > while(i < listOfSpanTags.size())
> > { // Beginning While loop to extract links
> > Span spanTag =3D
> > (Span)listOfSpanTags.elementAt(i);
> > // System.out.println(listOfSpanTags.size());
> > // We only need SPAN tags with attribute "class =3D
> > 'recenttimedate'"
> > // Move to the link in the span tag
> > if(spanTag.getText().equals("span class=3Drecenttimedate"))
> >
> > 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.
> >
> >
> >
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting langua=
ge
> that extends applications into web and mobile media. Attend the live webc=
ast
> and join the prime developer group breaking into this new coding territor=
y!
> http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=110944&bid$1720&dat=121642
> _______________________________________________
> Htmlparser-user mailing list
> Htm...@li...
> https://lists.sourceforge.net/lists/listinfo/htmlparser-user
>
>
>
> ________________________________
> Relax. Yahoo! Mail virus scanning helps detect nasty viruses!
>
>
|