-2

I am getting the following nullpointer exception in my code:

fieldName = "created";
Date startDate; 
DateFormat df = new SimpleDateFormat(this.dtFormatShort);
startDate = df.parse(doc.getCreated().getDateOnly() + " " + doc.getCreated().getTimeOnly()); //here I get the error
customer.setCreated(startDate);

I am using similar code across my app but there I do not nullpointer exceptions.

is the error related that I am not calling the constructor for the Date object first? and why does the exception not occur on other places of my app?

Patrick Kwinten
  • 1,988
  • 2
  • 14
  • 26

2 Answers2

1

I’m not sure why you’d get an NPE there (maybe the date format isn’t set), but you should be able to do something like doc.getCreated().toJavaDate() directly and save yourself the parsing headache.

Jesse Gallagher
  • 4,461
  • 13
  • 11
0

A Java constructor cannot return null. It either returns a non-null value or throws an exception. Therefore, df is not null.

The only other option is that either doc or doc.getCreated() are null. Either that or you've found a bug in the JVM.

P.s. calling the constructor for Date before reassigning it should do nothing w.r.t. a NPE being thrown in this code. But if you seriously think it's a JVM bug no harm in testing :)

cameron1024
  • 9,083
  • 2
  • 16
  • 36
  • of course I have checked if doc is not null. same code when running in dev environment does not result in error. same version of Domino, FP etc – Patrick Kwinten Nov 01 '19 at 10:42