Results 1 to 4 of 4
- 05-01-2012, 10:28 PM #1
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
Help With cannot find symbol method Error
Hi This is my first post so im sorry if its not in the correct format. Ive been trying to get the following code working. I keep getting an error.. cannot find symbol method add(competitor) when i try to compile. with line 62 competitors.add(runner); highligthed. I have tried changing List<String> competitors = new ArrayList<String>(); to List<Competitor> competitors = new ArrayList<Competitor>(); but this does not work and ive got myself confused! Can any one help?
Java Code:public class RaceAdmin { /* instance variables */ private String competitors; // replace this example variable with your own /** * Default constructor for objects of class RaceAdmin */ public RaceAdmin() { super(); List<String> competitors = new ArrayList<String>(); } /* instance methods */ /** * A public instance method that take no argument * and returns no value. Method reads from a file called * competitors.txt which contains pertinent information */ public void readInCompetitors() { String pathname = OUFileChooser.getFilename(); File compFile = new File(pathname); BufferedReader bufferedFileReader = null; try { bufferedFileReader = new BufferedReader(new FileReader(compFile)); String currentLine = bufferedFileReader.readLine(); String name; String sex; Integer age; String ageGroup; Scanner lineScanner; Integer time; while (currentLine != null) { lineScanner = new Scanner(currentLine); lineScanner.useDelimiter(","); Competitor runner = new Competitor(); runner.setName(lineScanner.next()); runner.setSex(lineScanner.next()); System.out.print("e"); age = lineScanner.nextInt(); if (age < 18) { runner.setAgeGroup("junior"); } else if (age > 55) { runner.setAgeGroup("senior"); } else { runner.setAgeGroup("standard"); } runner.setTime(Integer.parseInt(OUDialog.request(" Enter Time for Competitor: "))); currentLine = bufferedFileReader.readLine(); competitors.add(runner); } } catch (Exception anException) { System.out.println("An error has occur: " + anException); } finally { try { bufferedFileReader.close(); } catch (Exception anException) { System.out.println("An error has occur: " + anException); } } } }
- 05-01-2012, 10:34 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Help With cannot find symbol method Error
- 05-01-2012, 10:52 PM #3
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
Re: Help With cannot find symbol method Error
Thank you!
Thats seems to have worked, i cant believe it had me stuck for so long! I've amended my code to the following.. but i get an error uses unchecked or unsafe operation, how do I recompile wint -xlint:unchecked for details?
Java Code:public class RaceAdmin { /* instance variables */ private ArrayList competitors; // replace this example variable with your own /** * Default constructor for objects of class RaceAdmin */ public RaceAdmin() { super(); List<Competitor> competitors = new ArrayList<Competitor>(); } /* instance methods */ /** * A public instance method that take no argument * and returns no value. Method reads from a file called * competitors.txt which contains pertinent information */ public void readInCompetitors() { String pathname = OUFileChooser.getFilename(); File compFile = new File(pathname); BufferedReader bufferedFileReader = null; try { bufferedFileReader = new BufferedReader(new FileReader(compFile)); String currentLine = bufferedFileReader.readLine(); String name; String sex; Integer age; String ageGroup; Scanner lineScanner; Integer time; while (currentLine != null) { lineScanner = new Scanner(currentLine); lineScanner.useDelimiter(","); Competitor runner = new Competitor(); runner.setName(lineScanner.next()); runner.setSex(lineScanner.next()); System.out.print("e"); age = lineScanner.nextInt(); if (age < 18) { runner.setAgeGroup("junior"); } else if (age > 55) { runner.setAgeGroup("senior"); } else { runner.setAgeGroup("standard"); } runner.setTime(Integer.parseInt(OUDialog.request(" Enter Time for Competitor: "))); currentLine = bufferedFileReader.readLine(); competitors.add(runner); } } catch (Exception anException) { System.out.println("An error has occur: " + anException); } finally { try { bufferedFileReader.close(); } catch (Exception anException) { System.out.println("An error has occur: " + anException); } } } }Last edited by decon101; 05-01-2012 at 10:54 PM.
- 05-09-2012, 09:04 PM #4
Member
- Join Date
- May 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
cannot find symbol error, defined inside private method
By sp725 in forum New To JavaReplies: 7Last Post: 10-25-2011, 04:47 AM -
int cannot be dereferrenced, cannot find symbol method add
By felixnoriel in forum JCreatorReplies: 2Last Post: 03-08-2011, 03:08 PM -
HELP! can't find symbol-method
By Jack9333 in forum New To JavaReplies: 2Last Post: 03-04-2011, 01:48 AM -
this is the error i get: cannot find symbol method parseString(java.lang.String)
By Elcliff in forum New To JavaReplies: 10Last Post: 12-22-2010, 01:12 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks