I have defined two constructors in my code
public SAPRoleImpl()
{
dateParser=new SimpleDateFormat(MIDDAY_DATE_FORMAT);
dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
Calendar c=Calendar.getInstance(TimeZone.getTimeZone("GMT"));
c.set(Calendar.HOUR_OF_DAY,12);
c.set(Calendar.MINUTE,0);
c.set(Calendar.SECOND,0);
c.set(Calendar.MILLISECOND,0);
setStartDate(c.getTime());
}
public SAPRoleImpl(String formattedRole)
{
this();
...
}
When I execute the below code:
public static void main(String[] args) {
SAPRoleImpl sapRole = new SAPRoleImpl("abc|abcdesc||");
System.out.println(sapRole);
}
It gives this output
:abc|20170127||
This is as expected. But when I want an output of only
abc|||
i.e no start date is to be initialized, I tried this code:
public SAPRoleImpl()
{
}
public SAPRoleImpl(String formattedRole)
{
this();
...
}
This led to a NullPointerException
. Probably, It seems that the startdate
is null but I am not able to understand the reason behind the same.
Can any one please help me to understand?