Re: nullPointerException in abstract class




"OldPro" <rrosskopf@xxxxxxxxxxxxx> wrote in message
news:1191077477.541137.110830@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| 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/


.



Relevant Pages

  • Re: inheritance question
    ... the constructor of the Employee class should accept all parameters ... public Employee (DateTime DOB, string Address, string MaritalStatus, ... > private string mMaritalStatus; ...
    (microsoft.public.dotnet.languages.csharp)
  • Problem with Datagrid and OOP
    ... I have two different objects Employee and SalaryType ... public int Add ... private string _code; ...
    (microsoft.public.dotnet.languages.csharp)
  • Problem with Datagrid and OOP
    ... I have two different objects Employee and SalaryType ... public int Add ... private string _code; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Reflection in 1.1 and 2.0 - generic, fast copy delegate?
    ... Your delegate solution is is still significantly more efficient that reflection. ... Also you need permissions to emit code with the LCG version whereas using delegates does not appear to require permissions beyond those for public reflection and so you can have a fast solution even in low trust environments. ... private string _firstName; ...
    (microsoft.public.dotnet.framework.clr)
  • Re: EJB3 Newbie & Persistence
    ... private String name; ... CustomerCMP customer; ... public void setAddress{ ...
    (comp.lang.java.beans)