Error Code Help?

T

Tukewl4u

Can some one tell me why I'm getting this error? I really don't understand
why it shouldn't work.
Executing: C:\Program Files\ConTEXT\ConExec.exe "C:\Program
Files\Java\jdk1.5.0_07\bin\javac.exe" "GradeBookTest.java"

GradeBookTest.java:30: ')' expected
gradebook2.setCourseName ( String Name ); // set the course name
^
1 error
Execution finished.


From the following:

import java.util.Scanner;


public class GradeBookTest
{
// main method begins program execution
public static void main ( String args[] )
{



// create GradeBook object
GradeBook gradebook1 = new GradeBook( "CSCI 3134 Introduction to Java
Programming" );

GradeBook gradebook2 = new GradeBook( "Joe Schmo" );



// display initial value of courseName for each GradeBook
System.out.printf( "GradeBook for course name is: %s\n",
gradebook1.getCourseName() );

System.out.printf( "This course is presented by: %s\n",
gradebook2.getCourseName() );


// prompt for and read course name
System.out.println( "Please enter the course name:" );
String Name = input.nextLine(); // read a line of text
gradebook2.setCourseName ( String Name ); // set the course name
System.out.println(); // outputs a blank line

// display welcome message after specifying course name
GradeBook.displayMessage();





} //end main
} // end class GradeBookTest
 
T

Tukewl4u

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
 
J

Jean-Francois Briere

GradeBookTest.java:29: cannot find symbol
symbol : variable input

location: class GradeBookTest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top