954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Collection error can not find symbol (the noob needs help plz!)

Ok heres the problem Im working on a final project for a java course and one thing is blocking my path.

import java.util.*;


public class Controller {
public List list = new ArrayList();

public void addItem() {
CrewMember cm = Academy.load(
MenuUtil.getAString("Enter the role: "),
MenuUtil.getAnInt("Enter the id number: "));
if(cm!=null) list.add(cm);
else System.out.println("Load Failed; nothing to add");
}

public void removeItem() {
int i = (
MenuUtil.getAnInt("Choose the crew member you wish to remove '0' being first in the list: "));
list.remove(i);
}

public void displayItems () {
for(CrewMember item : list ) {
System.out.println(item);
item.action();
}
}

public void display(String s) {
ListIterator it = list.Iterator();
System.out.println(s);
while(it.hasNext()) System.out.println(it.next());
}

public void run() {
Collections.sort(list);
display("After Sort:");
}
}

Controller.java:37: cannot find symbol
symbol : method Iterator()
location: interface java.util.List
ListIterator it = list.Iterator();
^
Controller.java:43: cannot find symbol
symbol : method sort(java.util.List)
location: class java.util.Collections
Collections.sort(list);
^
2 errors

Process completed.

In this one class Im getting these two errors. I think it may have something to do with how I started the array list but since I'm new to coding in java it could be anything that I've done. Does anyone know why I'm getting these errors and how i can fix it?

Sseeth
Newbie Poster
6 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

1. Check your capitalisation! Java is case sensitive.
2. To make the sort meaningful your CrewMewmber class needs to implement Comparable, otherwize there's no way to know what the correct sort order for CrewMembers is.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

What line? My capitalization looks correct in my code to me, and im not sure why, must have been due to JCreator and i forgot to fix it but the little error arrows should be under the periods on Collections.sort and list.iterator

Sseeth
Newbie Poster
6 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Ok yeah it was the CrewMember class not implementing comparable. haha now i just have to figure out a way to do that. thanks.

Sseeth
Newbie Poster
6 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

The capitalisation was Iterator() vs iterator().
Comparable isn't too hard. For a quick start, you could just return the result of comparing the CrewMember's names (the String class implements Comparable already).

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

Yeah i just got it figured out. Thank you kindly, almost done now.

Sseeth
Newbie Poster
6 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You