W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2001

Re: nullpointer

From: Jim Ley <jim@e-media.co.uk>
Date: Thu, 31 May 2001 10:43:31 -0400 (EDT)
Message-ID: <005d01c0e9df$c2c45740$ca969dc3@emedia.co.uk>
To: "Tom Leuntjens" <tom.leuntjens@bricsnet.com>, "Www-Dom@W3. Org" <www-dom@w3.org>
> since I am getting nullpointer exceptions
> and i thought I am testing it using
> if (companyname.item(i).getFirstChild().getNodeValue() != null)
> apparantly that is not enough.

Nope, and it never is, this is a simple javascript problem because there
are no children to the item (say) then

companyname.item(i).getFirstChild() evaluates to null.
therefore you have

null.getNodeValue() != null
That is not allowed, null has no methods.

You need to test every single object  before calling a method/accessing a

if (companyname && companyname.item && companyname.item(i) &&
companyname.item(i).getFirstChild() &&

Would be what you want to do.  (yes I know it's long...)

Received on Monday, 4 June 2001 15:48:15 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:08 UTC