• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
reply
    Bookmark Topic Watch Topic
  • New Topic