when you know the variable you can put a simple if check around it or use the try catch block catching a NullPointerException.
So, for example if the variable in question is a String called var1
-
-
if(var1 != null && var1.length() > 0)
-
{
-
// use the variable
-
}
-
else
-
{
-
// handle the exception
-
}
-
Alternatively using the try catch method:
-
try{
-
// use the variable var1
-
}catch(NullPointerException npe){
-
System.out.println(npe.getMessage()); // not production ready
-
}
-
This is the way I would go, the finl suggestion is that if it is appropriate set up the variable with a default value.
Hope this helps
nathj