I am trying to setup a membership system, and want to implement a start and end date. I think I have successfully implemented the starting date, however, I am having a tough time with the expiration date (1 year later). The expiry should be stored in a text field which is a String
, thus it needs to be converted. However, on compilation, I am presented with a NullPointerException
.
center.add(createLabel("Membership Date Created"));
center.add(memDateCreatedTxtFld);
SimpleDateFormat sdf = new SimpleDateFormat ("E yyyy/MM/dd");
Date date = new Date();
memDateCreatedTxtFld.setText(sdf.format(date));
center.add(createLabel("Membership Date Expiry"));
Calendar cal = Calendar.getInstance();
Date today = cal.getTime();
cal.add(Calendar.YEAR, 1);
Date nextYear = cal.getTime();
String reportDate = sdf.format(nextYear);
memDateExpiryTxtFld.setText(reportDate);
center.add(memDateExpiryTxtFld);
For example, since today is 2019/02/01, the expiry should be on 2020/02/01.