Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.Vector  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello after a while, I'm trying now to make Vector of Object[], but i'm getting an exception i posted below.

This is a part of my code, which i think is causing this exception.

My question is how can i modify my code to work properly. I know i can do Vector of Vectors, but it's a long way, and i wondering is there any shortcut? Any suggestions are welcome.
PS. zawodnicyAtaku[] is an array of strings, and vectorWierszy is used in constructor of DefaultTableModel.
 
Sheriff
Posts: 21747
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DefaultTableModel wants a Vector<Vector<?>> (a Vector of Vectors), not a Vector<Object[]> (a Vector of Object arrays). This is explained on the DefaultTableModel Javadoc page:

This is an implementation of TableModel that uses a Vector of Vectors to store the cell value objects.


It would be better if the API actually reflected that, so no raw Vector but instead Vector<? extends Vector<?>>. Note that the ? extends is required to allow Vector<Vector<Integer>> or even Vector<Vector<Object>>; with Vector<Vector<?>> the compiler allows nothing except a literal Vector<Vector<?>>.
 
Radek Gajdos
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob for your advice, i used Vector<Vector<Object>> in my code and it works fine. Some working code below.

Best regards!
 
Rob Spoor
Sheriff
Posts: 21747
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!