Class with inner class array for storage getting NullPointerException
abhillz_at_mail.com
Date: 02/16/05
- Next message: klynn47_at_comcast.net: "Re: Class with inner class array for storage getting NullPointerException"
- Previous message: klynn47_at_comcast.net: "Re: Disadvantages of "instanceof""
- Next in thread: klynn47_at_comcast.net: "Re: Class with inner class array for storage getting NullPointerException"
- Reply: klynn47_at_comcast.net: "Re: Class with inner class array for storage getting NullPointerException"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 15 Feb 2005 18:07:08 -0800
Yay, I got my first java.lang.NullPointerException(NPE) =) Here's my
complete code:
http://demos.home.mchsi.com/payroll.java
It's an employee gross program that computes reg and overtime pay/hours
and totals for as many employees as the user wants. It's for my first
class on java.
I've been searching alot about class arrays & NPEs but found little,
this is the best clue I've found about NPEs:
http://jeremy.zawodny.com/blog/archives/000422.html
Here's the important code, the inner class of payroll, the
instantiation(s), and the method that is supposed to record in the
storage(inner)class. The record method/storage class is definately the
cause of this NPE. I'll post exactly what JGrasp is returning on run
after the code.
private class storage
{ private String name="";
private double hours=0, rate=0, regHrs=0, regPay=0, ovtHrs=0,
ovtPay=0;
} /*After reading http://jeremy.zawodny.com/blog/archives/000422.html
I decided to declare the var.s so they were not null..no luck*/
/*class array storage*/
storage pay[] = new storage[emps];
/*reocrd-*/private void record()
{pay = new storage[emps];
pay[c].name = name;
pay[c].hours = hours;
pay[c].regHrs = regHrs;
pay[c].ovtHrs = ovtHrs;
pay[c].regPay = regPay;
pay[c].ovtPay = ovtPay;
}
...inputing info...then it hits record(); and BAM:
Exception in thread "main" java.lang.NullPointerException
at payroll$storage.access$002(payroll.java:37)
at payroll.record(payroll.java:47)
at payroll.start(payroll.java:28)
at payroll.main(payroll.java:131)
----jGRASP wedge2: exit code for process is 1.
- Next message: klynn47_at_comcast.net: "Re: Class with inner class array for storage getting NullPointerException"
- Previous message: klynn47_at_comcast.net: "Re: Disadvantages of "instanceof""
- Next in thread: klynn47_at_comcast.net: "Re: Class with inner class array for storage getting NullPointerException"
- Reply: klynn47_at_comcast.net: "Re: Class with inner class array for storage getting NullPointerException"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]