Today when I wanted to get information from database and load it on screen,to my surprise I saw nothing. I tried to figure out this problem and later I got it.It is because one field of a record was empty.When I used data of this field with function toString(),it caused java.lang.NullPointerException problem.But I didn’t find it at first because it entered the exception handler .It returned null as a result so nothing loaded.And later I tested this question in my computer.Below is the result.
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = null;
System.out.println(str.toString());
}
}
Conlustion:
When extract data anywhere,we should consider whether it’s empty.If it’s empty,set a default value.