Get rid of String before name between the parenthesises.
Ok, I'm a little confused. I've thought that, but what does 'cannot find
symbol' mean? Does something need to be specified in the object? I'm trying
to modify Small Java Fig. 3.7-3.8
http://www.cs.unt.edu/~irby/Courses/1030/programs/SJch3.html to a class
project and don't see the difference. To me...it should work. Now I get:
> Executing: C:\Program Files\ConTEXT\ConExec.exe "C:\Program
Files\Java\jdk1.5.0_07\bin\javac.exe" "GradeBookTest.java"
GradeBookTest.java:29: cannot find symbol
symbol : variable input
location: class GradeBookTest
String name = input.nextLine(); // read a line of text
^
GradeBookTest.java:34: non-static method displayMessage() cannot be
referenced from a static context
GradeBook.displayMessage();
^
2 errors
> Execution finished.
> Get rid of String before name between the parenthesises.
Jean-Francois Briere - 25 Sep 2006 19:45 GMT
> GradeBookTest.java:29: cannot find symbol
>
[quoted text clipped - 3 lines]
>
> String name = input.nextLine(); // read a line of text
Compile error messages are there to help you understand what is wrong
with your code.
Don't be afraid of them. You can learn a great deal only by looking at
the error messages.
Sometimes the messages aren't so clear but it at least give you a
general idea of what is going wrong.
The first error message cearly states:
"cannot find symbol: variable input"
This means that the compiler saw 'input' as a variable but was unable
to know type.
All Java variables must have a type.
To do so they must be declared with their type.
The reason for the error is because you got rid of the (previous) line:
Scanner input = new Scanner( System.in );
where clearly the variable 'input' is declared of type Scanner.
> GradeBookTest.java:34: non-static method displayMessage() cannot be
> referenced from a static context
>
> GradeBook.displayMessage();
The second message is:
"non-static method displayMessage() cannot be referenced from a static
context"
That's because you wrote:
GradeBook.displayMessage();
which means : call the static method of the GradeBook class.
but since the displayMessage() method is not static (in the GradeBook
class declaration) then you get the error.
Before your modification it was written like this:
GradeBook myGradeBook = new GradeBook();
...
myGradeBook.displayMessage();
which means: 1- create an object of type GradeBook
2- call the object's (non-static) method displayMessage().
And that was working.
Regards
Tukewl4u - 27 Sep 2006 03:21 GMT
Got it. Thanks for the help Jean! I just have to learn the syntx errors.
>> GradeBookTest.java:29: cannot find symbol
>>
[quoted text clipped - 51 lines]
>
> Regards