Avoiding null pointer exception
by , 11-01-2011 at 05:26 PM (636 Views)
One should try avoiding null pointer exception. In case of coding an application that needs high degree of reliability, don't take risks. I will present an example.
Check the following piece of code.
It seems a normal piece of code. But still there's a hidden trap here. What is the string which is passed is null? So try to rephrase the code as given below.Java Code:private boolean isNullString(String string) { return (string.equals("")); }
This should work now without any null pointer exceptions.Java Code:private boolean isNullString(String string) { return ("".equals(string)); }









Email Blog Entry
sorry for all the questions
thanks...
06-14-2013, 02:22 PM in gbonecapone