This discussion is archived
1 2 Previous Next 17 Replies Latest reply: Jan 12, 2010 3:12 AM by 800268 RSS

Can't typecast Object array to other type

807580 Newbie
Currently Being Moderated
Label labels[] = (Label[])(list.toArray()); //fails
Label labels[] = new Label[list.size()];
int i;
for (i=0; i<list.size(); i++) {
   labels[i] = (Label)list.get(i);
When ever I try the first code I get this exception:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lmips.Label;
Am I typecasting wrong?
1 2 Previous Next