Why null pointer exception is thrown ?