• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot find symbol error -- what am I missing

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic