I have a class CommonDaoImpl that implements an interface CommonDao. Now i am trying to access the getRegisterData() of CommonDaoImpl through interface CommonDao reference like this
public class CommonServiceImpl implements CommonService
{
CommonDao commonDao
public boolean insertRegisterData(CommonBean objCommonBean) {
return commonDao.getRegisterData(objCommonBean);
}
but it is not working and thow an NullPointerException
So i slightly change my code and initialize interface reference with the constructor of implemented class CommonDao impl like this
public class CommonServiceImpl implements CommonService
{
CommonDao commonDao=new CommonDaoImpl();
public boolean getRegisterData(CommonBean objCommonBean) {
return commonDao.insertRegisterData(objCommonBean);
}
But i could not understand why it happens.
