Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 5th, 2006, 11:51 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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.
Eric the Red is offline   Reply With Quote
Old Apr 5th, 2006, 11:53 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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
Mjordan2nd is offline   Reply With Quote
Old Apr 5th, 2006, 11:55 PM   #3
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Quote:
Originally Posted by Mjordan2nd
LicenseTime [intNumberofLines - 1]has never been initialized.
sorry i didn't include that. But I have initialized it
CalendarTime LicenseTime [] = new CalendarTime [intNumberofLines];
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old Apr 5th, 2006, 11:59 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 928
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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();
Notice that licenseTime should start with a lowercase letter as it is a variable.
titaniumdecoy is offline   Reply With Quote
Old Apr 6th, 2006, 12:02 AM   #5
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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.
Eric the Red is offline   Reply With Quote
Old Apr 6th, 2006, 12:13 AM   #6
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 928
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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;
}
You could use it like this:

CalendarTime[] licenseTime = CalendarTime.createCalendarTimeArray(intNumberofLines);
(This probably isn't a good idea; it was in response to the question you posted previously but erased.)

Last edited by titaniumdecoy; Apr 6th, 2006 at 12:24 AM.
titaniumdecoy is offline   Reply With Quote
Old Apr 6th, 2006, 12:24 AM   #7
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Quote:
Originally Posted by titaniumdecoy
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;
}
You could use it like this:

CalendarTime[] licenseTime = CalendarTime.createCalendarTimeArray(intNumberofLines);
thanks A lot!
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:26 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC