If there is a chance that you might get null pointer then please use use try catch block , in this case it is a null pointer exception.