![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
null pointer
Would someone please be able to tell me why i'm getting an error in the blue writting? it states "attempt to use a null pointer" (java.lang.NullPointerException)"
If you need the full code let me know. Do you think that the array is out of bounds or is there something else to the error? class CalendarTime
{
public long milli;
public long minute;
public long rightNow;
public long rightThen;
public Calendar Now;
// contructor
public CalendarTime ()
{
Now = Calendar.getInstance ();
this.milli = Now.getTimeInMillis (); // contructs current time
this.minute = this.milli / 60000;
this.rightNow = this.minute;
this.rightThen = this.minute + 10; //default is 10 minutes.
}
// used to set a different time limit
public void setTime (int x)
{
this.rightThen = (Now.getTimeInMillis () / 60000 + x);
}
public long getTimeLeft ()
{
return this.rightThen - this.rightNow; // time left
}
public long getThen ()
{
return this.rightThen;
}
}
LicenseTime = new CalendarTime [intNumberofLines + 1];
c.print ("time = :" + LicenseTime [intNumberofLines - 1].getThen ());
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
LicenseTime [intNumberofLines - 1]has never been initialized.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Quote:
CalendarTime LicenseTime [] = new CalendarTime [intNumberofLines];
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
|
#4 |
|
Expert Programmer
|
When you create a new array of objects, each index of the array defaults to null. Therefore, you have to initialize each index:
for (int i = 0; i < intNumberofLines; i++)
licenseTime[i] = new CalendarTime(); |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
From what you told me it works perfect, Thanks!
__________________
Death smiles at us all. All a man can do is smile back. Last edited by Eric the Red; Apr 6th, 2006 at 12:13 AM. |
|
|
|
|
|
#6 |
|
Expert Programmer
|
If you wanted to, you could add a method like the following to the CalendarTime class:
private static CalendarTime[] createCalendarTimeArray(int size) {
CalendarTime[] t = new CalendarTime[size];
for (int i = 0; i < size; i++)
t[i] = new CalendarTime();
return t;
}CalendarTime[] licenseTime = CalendarTime.createCalendarTimeArray(intNumberofLines); Last edited by titaniumdecoy; Apr 6th, 2006 at 12:24 AM. |
|
|
|
|
|
#7 | |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Quote:
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|