It is currently Sat Oct 20, 2018 4:11 pm Advanced search

JAVA. Tutorial step 2 error mesages

Topics about starter packages, visualizer or any other third party tools.
Please submit new language requests in the Language Request Forum.

JAVA. Tutorial step 2 error mesages

Postby wizardrahl » Mon Nov 07, 2011 9:36 am

I'm trying to follow the tutorial and just finished step 2 and when I try to run it locally i get these error messages.

Exception in thread "main" java.lang.ClassCastException: Tile cannot be cast to
at Source)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at java.util.TreeSet.addAll(Unknown Source)
at java.util.TreeSet.<init>(Unknown Source)
at MyBot.doTurn(
at AbstractSystemInputParser.processLine(
at AbstractSystemInputReader.readSystemInput(AbstractSystemInputReader.j

I'm still pretty new to programing so I'm not exactly sure what this means or what the problem could be. Any help would be greatly appreciated. THX
Posts: 10
Joined: Fri Oct 21, 2011 4:28 pm

Re: JAVA. Tutorial step 2 error mesages

Postby CarolineM » Sun Nov 13, 2011 8:57 pm

I had the same problem and fixed it by changing the two TreeSet<Tile> instantiations in doTurn() to Set<Tile>:

Set<Tile> sortedFood = ants.getFoodTiles();
Set<Tile> sortedAnts = ants.getMyAnts();

TreeSet uses a Comparator to put the elements that you insert into it into the correct order, but Tile does not implement Comparator, so you get an exception. Another solution would be to implement Comparator in Tile.

I don't see the point in sorting the food and the ants because we sort all possible Routes later in the method.
Posts: 1
Joined: Sun Nov 13, 2011 8:42 pm

Return to Starter Packages & Tools

Who is online

Users browsing this forum: No registered users and 5 guests