Re: nullPointerException in abstract class
"OldPro" <rrosskopf@sbcglobal.net> wrote in message
news:1191077477.541137.110830@22g2000hsm.googlegroups.com...
| Why is this giving an error? birthDate is properly initialized, isn't
| it?
|
| public abstract class Employee
| {
| private String firstName;
| private String lastName;
| private String socialSecurityNumber;
| private Date birthDate;
|
| // three-argument constructor
| public Employee( String first, String last, String ssn, String
| birth )
| {
| firstName = first;
| lastName = last;
| socialSecurityNumber = ssn;
| birthDate = new Date(); // Here is where the error occurs (it
| doesn't stop the program)
| birthDate.setDate(birth);
| } // end three-argument Employee constructor
|
I don't see how the line you've marked could cause a NullPointerException.
Furthermore, if it did, it would certainly stop the program at that point.
Are you sure this is the code you're running--I don't think it is. The
following line would probably produce NPE when birth is null, but the
exception will be thrown in the normal way. The error is probably in parts
of code that are not shown, like whomever calls this. Also, you're
three-argument constructor has four arguments.
Matt Humphrey http://www.iviz.com/