Re: unbelievable NullPointerException
hi again, so here is a more details description of my problem:
Here is the code of my class :
public class CenterService {
public CenterDAO centerDao = null;
public CenterService(){
centerDao = new CenterDAO();
}
public List<Center> getCenters() throws DAOException{
return centerDao.getCenters();
}
public Center getCenter(int centerId) throws DAOException{
for (Center center: getCenters()){
if(center.id.intValue()==centerId) return center;
}
return null;
}
}
When I do following code :
CenterService service = new CenterService();
Center center = service.getCenter(5); --> Null pointer exception is
thrown at this line (not in line of body of the getCenter(int) method
If I use following code, the result is the same:
Center center = new CenterService().getCenter(5); --> same
NullPointException.
I've also tried to use class variable with same result.
More over, in fact, in the code, I create a conference object, and when
I want to fill it, the gets the center from DB. The I call the method
that contains this code the first time, this works well. When I call it
the second time with from the same instance of conference, this throws
the exception. If the second Time I use a new conference to fill it,
this does not throw the NullPointerException.
We have rebuid build the code on a production-like workstation used by
tester, the problem also appears. The problem appears when I launch
JUnit test to create my conferences that call the getCEnter() method,
or also in the global code of the server.
THanks.