• Post Reply Bookmark Topic Watch Topic
  • New Topic

Empty JTable data causes array index exception  RSS feed

 
John Deal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple JTable that then my application first starts up is empty then gets populated based on user actions which can result in it being empty at later states of the program. When the program does start it will get an ArrayIndexOutOfBounds exception with a parameter of '1' which I assume is the index value that caused the problem. However the program continues running fine and force the data of the JTable to be empty with no ill effects.

The interesting part is this only happens the first time the program starts up. I can kill the program and any other Java programs running, then start it up again and I will not get this problem. To duplicate the problem, I have to restart the computer (Windows XP SP2).

The creation of the JTable is similar to the following:

---------------------------------------------------------
private final static String [] COLUMN_NAMES=
{"XXX", "YYY", "ZZZ"};

.........

ArrayList<DataRecord> data; // Gets loaded elsewhere

........

Object [][] tableData = new String [data.size()][COLUMN_NAMES.length];

........

dataJTable = new JTable(tableData, COLUMN_NAMES);

---------------------------------

When the first time the program starts up the ArrayList jobs is an empty list (jobs = new ArrayList<DataRecord>()) so its size is zero (0). What I want to happen in this case and does happen is for JTable to just display the column headings. Only on the first time the program is run after the computer has been started do I get the above mentioned exception. BTW I am using JRE 1.5.0_12 and JDK 1.5.0_12.

If I force a blank data record into data ArrayList (making it a size of one (1)) it works but JTable displays a data row that I would prefer not to have there.

Any ideas? Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!