• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange ClassCastException working with JTable

 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I've had all kinds of difficulties working with JTable so far.
I am working with a very simple table. Originally, I constructed it like this:The data is not known at the time of construction which is why I was passing a null Vector for the dataRows param.
That code worked fine from my PC but the JTable constructor threw NullPointerExceptions on another PC. Both PCs were running java 1.4.2_05.

So, since one JVM seemed to not like the null dataRows, I created an empty dataRows Vector, like this:: That fixed the NPE's and both PC's seemed to be happy.

However, now I am running into another strange problem with this code:As you can see the intent is to simply remove all rows from a table. But on [B]one[B] PC, I am getting a ClassCastException in that method. On the other PC, it works fine.

Anyone experience this?
Why would table.getModel() on one PC using the same JRE return something other than DefaultTableModel???
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you absolutely sure both machines are running the same Java version? If you run java -version on the command line, you get the same?
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Andrews:
Are you absolutely sure both machines are running the same Java version? If you run java -version on the command line, you get the same?
Correct.
Even if the version was slightly different, I don't see why the cast would break. As far as I understand TableModel usage, if you don't explicitly use one (e.g. if you use the JTable(Vector, Vector) constructor), then you get a DefaultTableModel. Arghhhh
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Do not know if it help you, but vector which contains the table data must be Vector of Vectors(every Vector inside must represent one row in the table), in other way DeafaultDataModel will not understand this construction.
[ July 20, 2004: Message edited by: Serghei Jelauc ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!