| Author |
JTable ClassCastException: Add rows dynamically
|
Sherry Jacob
Ranch Hand
Joined: Jun 29, 2005
Posts: 128
|
|
Hi Everyone, Heres what I wrote to implement a simple JTable. Can anyone tell me why this code gives a the following runtime error of ClassCastException? ---------- Run Java File ---------- java.lang.ClassCastException: java.lang.String at javax.swing.table.DefaultTableModel.justifyRows(DefaultTableModel.java:238) at javax.swing.table.DefaultTableModel.setDataVector(DefaultTableModel.java:194) at TablePopulation.<init>(TablePopulation.java:36) at TablePopulation.main(TablePopulation.java:49) Exception in thread "main" Output completed (3 sec consumed) - Normal Termination [ March 17, 2006: Message edited by: Sherry Jacob ]
|
<strong><br />Cheers !!<br /> <br />Sherry<br /></strong><br />[SCJP 1.4]
|
 |
Ben Zung
Ranch Hand
Joined: Mar 25, 2004
Posts: 109
|
|
Sherry, The first parameter should be a Vector of Vectors for setDataVector. Try add the "rows" returned to a new Vector and use it as the first param of setDataVector. It makes sense coming to think that a table is a two dimension presentation of data. The cause of your problem is that with your initializing of the table model, a String was being tried to cast into a Vector thus the error. Good luck. [ March 17, 2006: Message edited by: Ben Zung ]
|
 |
Ben Zung
Ranch Hand
Joined: Mar 25, 2004
Posts: 109
|
|
By the way, show() is a method inherited from Window which has been deprecated. You may want to stay away from it -- or rather all those deprecated. Use setVisible() works. Also, you probably want to pay some attention to type safety. ie I would parameterize cols like this Have fun! [ March 17, 2006: Message edited by: Ben Zung ]
|
 |
 |
|
|
subject: JTable ClassCastException: Add rows dynamically
|
|
|