• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Radek Gajdos
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.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java 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: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!