![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
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++; |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
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
} |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jun 2005
Posts: 28
Rep Power: 0
![]() |
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)
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|