• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot find symbol error -- what am I missing  RSS feed

 
Christopher Laurenzano
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a little horse racing program to learn Java (been a while, but am getting back into it).

What this class and its methods do is ask the user to enter the name of the horses he'd like to race, then add them to the entryList Array List, then ask if he wants to scratch any horses. After that then the horses are randomly assigned their post positions in the setRaceField () method, assigning the positions for the race (which currently is the index of each horse, randomly assigned; which I'm still working on how to do).

Here's the code.



The problem occurs in lines 62 and 115. When I compile the class I get these error messages:

race.java:62: error: cannot find symbol
entryList.setRaceField();
^
symbol: method setRaceField()
location: variable entryList of type ArrayList<thoroughbred>
race.java:115: error: cannot find symbol
entryList.setRaceField();
^
symbol: method setRaceField()
location: variable entryList of type ArrayList<thoroughbred>
2 errors


if a just use setRaceField(); it compiles and runs(there's not code in the method yet, but it runs and just ends and gives me back my prompt in Terminal.) even if i do put code in there such as a simple print line, I still get the error messages

So why can't I call the method on the ArrayList entryList? again it's probably something simple, but I just don't get it.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call only those methods on ArrayList which it has defined or it inherits from its parent classes. This is true for all the objects in Java. You can invoke only those methods which a class defines or inherits from its parent class. In this example the method setRaceField is not defined in ArrayList or in any of its parent classes.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing which I noted in your code is that you need to work on the java code conventions. The best place to start is our own Javaranch Style Guide.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have had to reformat much of that code: breaking the long lines and the long // type comments and the excess blank lines which don&apos't add to legibility.
Don't use double apostrophe: use \" instead. Don't use tabs for indenting: get a decent text editor and it can convert your tabs to the right number of spaces.
 
Christopher Laurenzano
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips on coding conventions; forgot about those.

I use text editor on my Mac, but it doesn't allow me to change the tabs, I don't think.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!