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<CrewMember> list = new ArrayList<CrewMember>();

  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<CrewMember>
    ListIterator it = list.Iterator();
                          ^
Controller.java:43: cannot find symbol
symbol  : method sort(java.util.List<CrewMember>)
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?

Recommended Answers

All 5 Replies

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.

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

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

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).

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.