• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot find symbol  RSS feed

 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





Any help would be appreciated.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, can't you work out the reason for that error message? What does it say in the line with the error? Where is the line with the error? It isn't in the code you posted.

Apart from the fact that it looks very dubious to call a bit of text a list, and your text will come out looking very peculiar.
Find out why using += on Strings in a loop can cause slow execution, too.
Remove the keyword static from your vocabulary.
What do the above average and below average variables mean? Why are you changing them in a method which is supposed to create a list of runners?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's not in this file...

The compiler error says :

BanffMarathonRunner.java:140: error: cannot find symbol
                                System.out.println(runnerList);

You need to look in the BanffMarathonRunner.java class at line 140, where you are trying to print runnerList, not in the getAboveAverageRunners method...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Cannot find symbol" means that you are using a variable name, method name or class name in your code at a point where that name isn't defined.

The error message says that the error happens in line 140 of BanffMarathonRunner.java. Which line of the code that you posted is line 140?

Note that variables have a scope, which is normally delimited by { and }. For example, a variable defined inside the { and } of a method, does not exist outside of the method. If you try to use that variable outside of its scope, the compiler will not understand what you mean and will give you a "cannot find symbol" error.
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not posting the other portion of the code here it is



trying to display the runners who have a faster running time than the average.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and nowhere in your main method do you have a variable named "runnerList". 

You probably need to call your getAboveAverageRunners() method and save what it returns to a String (which probably should be named runnerList based on your code), and then print THAT string.
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and nowhere in your main method do you have a variable named "runnerList". 

You probably need to call your getAboveAverageRunners() method and save what it returns to a String (which probably should be named runnerList based on your code), and then print THAT string.


i added the variable String runnerList;

how do I call that method and save it to a string? thats what I was trying to do with the runnerlist, Im pretty new and have lots to learn.
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not..
This assumes that your BanffMarathonRunner class has implemented the toString() method.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Gordon wrote:i added the variable String runnerList;

That a good start...
how do I call that method and save it to a string? thats what I was trying to do with the runnerlist, Im pretty new and have lots to learn.

What method?  What is its return type?
 
Ryan Gordon
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is what I have so far I tried to use String toString but sill receiving errors. I feel stuck not sure what to do...

These are the newest errors

 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have the method return an array of runners instead, then your calling program can process the array in whatever manner it chooses.

This would work best with Lists but if you're limited to using arrays then you'd have to make two passes through the data, the first to count the number of above average runners, then allocate a runner array of that size, and then make a second pass through the data populating the array with only the above average runners.
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Essentially, the pseudo code for this is...

       
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Gordon wrote:. . . i added the variable String runnerList; . . . .
Nonononononononono

Apart from the fact that you now have two runnerList variables in different locations, each independent of the other:-
You need to get that code out of the main method and into the rest of the code. As you will see here, the ideal length of a main method is one statement:-Remove all other code from the main method; it doesn't belong there, and delete all other occurrences of the keyword static. You now have to decide which methods of the Marathon class (or other class) the instructions removed from main() belong in.
 
Liutauras Vilda
Sheriff
Posts: 4918
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have lots of little technical problems as in within your setter methods, where you re-assign value to the same variable, meaning having no effect to instance fields.

But I don't think that is your main problem. Your main problem in my opinion is not being disciplined in writing code. You wrote so much of it, which looks like a try to catch up with submission deadlines without paying attention to quality. Probably quality isn't the right word here, more correct would be 'correctness' first.

When you write program, how you ensure it does what it needs to do? You got some compilation error at the moment, but I believe problems started way more often than that. So how you test your program?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Gordon wrote:


Why does your class BanffMarathonRunner extend class AddressBook? That looks really strange. Remove the "extends AddressBook", I don't see a good reason why BanffMarathonRunner should extend AddressBook.

You get the "incompatible types" error because you declared that the method getAboveAverageRunners returns a String:
Ryan Gordon wrote:


But the variable aboveAverageRunners is a BanffMarathonRunner (line 88); in line 100 you are returning this variable from the method, but it's wrong because the method must return a String and not a BanffMarathonRunner.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!