You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by Kevin Smith <ke...@electricanvil.com> on 2002/11/19 21:09:22 UTC

Re: null pointer Exception

Another trick is to flip string comparisons and put the string literal on the 
left hand side:

if("whatever".equals(theString))

This eliminates the need to check if theString is null.

--Kevin
On Tuesday 19 November 2002 10:12 pm, Phillip Andrews wrote:
> Mike,
>
> This could have nothing to do with your problem, but I've only ever
> encountered the error "java.lang.NullPointerException" when I'm don't test
> for null properly.
>
> Try things like      if (thingy != null) {
>   		    thenDoSomething()
> 		  {
> before you get to any comparing of strings.
>
>
> Also avoid comparing Strings like    if ( theString=="whatever") etc...
> Try instead 	if ( theString.equals("whatever")) etc....
>
> Or try a combination of both in your code..
>
> Good Luck
>
> Phil Andrews (UK)