Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jun 3rd, 2005, 8:23 AM   #1
HeX
Programmer
 
HeX's Avatar
 
Join Date: May 2005
Location: Kosova
Posts: 94
Rep Power: 4 HeX is on a distinguished road
Send a message via MSN to HeX
Null Pointer Exception

I am writing an appointment manager. The first frame of the program has 31 buttons (days of a month), when I click a day, another frame shows the appointments made on that day. I made it so that the appointments titles are shown in a JList, and then if you click in a title another frame comes out and shows the description of that appointment.
I also wrote a class Database in which the titles and descritpions of the appointments are stored in a two-dimensional array (ie. descritpion[day][title]).
The problem is that when the program executes the first time, after I click on a day of the month, it thrws a Null Pointer Exception, because the JList takes the titles from the database, and when it is executed the first time, the database is empty.

Any suggestion how to avoid this?
__________________
countdown++;
HeX is offline   Reply With Quote
Old Jun 3rd, 2005, 9:59 AM   #2
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
put a dummy record in the database or initialize the array to " ".
you can also use exception handling
i don't know if its the same in java but in c#:
try{
//the code that throws the exception goes here
}
catch(Exception ex)
{
//do something to handle the exception
}
i hope this helps
OpenLoop is offline   Reply With Quote
Old Jun 4th, 2005, 9:49 PM   #3
Knight
Newbie
 
Join Date: Jun 2005
Posts: 28
Rep Power: 0 Knight is on a distinguished road
Thats right, OpenLoop, for the Java code. It may be a good practice to start initializing the variables to something when you declare them (atleast for me, I find it very handy)
Knight 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 12:45 AM.

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