This site requires JavaScript, please enable it in your browser!
Greenfoot back
kangmj
kangmj wrote ...

2014/10/6

Can't find a mistake

kangmj kangmj

2014/10/6

#
There is no syntax errors, but it doesn't works after compiling it shows java.lang.ClassCastException: java.util.ArrayList cannot be cast to Cards Cards list = new Cards; for (int i = 0; i <= cards-1; i ++){ this.setLocation(55 + 75*i, 165); list = (Cards)getOneIntersectingObject(Cards.class); }
danpost danpost

2014/10/6

#
The last line does not look bad; but, the first line is questionable. Also, the name of the field, 'list', is strange, when the variable holds a Cards object, not a list. It does not appear that the variable 'list' is used between being assigned a value in the first line and being assigned another in the last. Maybe you should just set the variable to 'null' to begin with.
davmac davmac

2014/10/7

#
I have a lot of trouble believing that the code you posted actually compiles. In any case, please use 'code' tags when posting code. See this link.
Super_Hippo Super_Hippo

2014/10/7

#
It looks like you want to create a list with all cards in it. If it is this case, you can get a list of all cards with:
getWorld().getObjects(Cards.class);
You need to login to post a reply.