I am reading a file and sorting a list, and I cannot figure out why I am getting an error on line 15 that contains the following code
Collections.sort(sortedContributorList, new Contributor());
This is the error I keep getting:
The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (LinkedList<Contributor>, Contributor)
import java.util.*; import java.io.*; public class myhashTable { public static LinkedList<Contributor> sortedContributorList = new LinkedList<Contributor>(); public myhashTable(){ } public void sortedLL(){ readFile(); Collections.sort(sortedContributorList, new Contributor()); printSortedList(sortedContributorList); } private static void readFile() {//opens a private method for reading the contributor.csv file String fileLocation ="C:address/here.csv"; //variable to hold the file String readLine;//sets the variable to read the lines within the file BufferedReader csvBuffReader;//calls the reader to read the text from a character-input stream try// {//opens a try condition. In this instance we are trying to read a file csvBuffReader = new BufferedReader (new FileReader(fileLocation));//creates a new reader for reading the .csv file while ((readLine = csvBuffReader.readLine()) != null)//creates a while loop and condition for reading the line {//opens the while loop... the condition states, while there are lines to read, keep reading them, when the line is empty, stop reading Contributor contributors = createContribList(readLine);//creates a new linked list/stack to store the contents of the read file addToList (contributors);//as the file is being read, this places the information into a linked stack }//closes the while loop }//ends the try condition catch (IOException e)//presents a solution for handling an error if the try was unable to import the file or export data to a file {//opens the catch block System.out.println(e.toString());//if an error occurs, the error handler would print an error message to screen }//ends the catch block System.out.println("Reading the CSV file was successful.");//prints message to the screen }//end public static Contributor createContribList (String line){ final String LL = ", ";//sets the variable to read the line until a comma appears, then proceeds to call that string a token StringTokenizer lineToken;//breaks the lines of text into desired strings for enhanced readability int tokenNumber = 0;//sets and initializes the variable Contributor sortedList = new Contributor();//creates a new linked list/stack for storing information from the file lineToken = new StringTokenizer(line, LL);//creates a new tokenizer for breaking the lines of information into appropriate sections while(lineToken.hasMoreTokens()){ // while loop to set conditions to set data with tokennumber as long as it has more tokens switch (tokenNumber){// sentinel switch to move tokenizer and set data in variables with data types case 0: sortedList.setFirstName(lineToken.nextToken()); break; case 1: sortedList.setLastName(lineToken.nextToken()); break; case 2: sortedList.setCountry(lineToken.nextToken()); break; case 3: sortedList.setPhoneNumber(lineToken.nextToken()); break; case 4: sortedList.setContributorAmount(Double.valueOf(lineToken.nextToken())); break; case 5: sortedList.setId(Integer.valueOf(lineToken.nextToken())); break; }//ends the switch condition for placing tokenized data into the appropriate sections tokenNumber++;//Increments the token number so that each token is read }//ends the while loop return sortedList;//returns the tokenized and switched information }//ends the private method for storing the switched and tokenized data read from a file public static void addToList(Contributor LL)//method to add data to LL {//opens the private method sortedContributorList.add(LL);//add the data into each node of the linked list/stack }//closes the private method public static void printSortedList(List<Contributor> lL)//prints info in the linked list/stack {//opens the private method Contributor currentSort;//sets the variable for the linked list for (int count=0;count<lL.size(); count++)//creates a loop for reading the linked list/stack. once the stack is empty the compiler stops reading {//opens the for loop currentSort = lL.get(count);//get the information System.out.println("Contributor # " + (count+1));//header System.out.println();//formatting readability currentSort.printContr();// prints nodes }//ends the for loop } }