• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Strange ClassCastException working with JTable

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic