Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Error Code Help?

Thread view: 
Tukewl4u - 24 Sep 2006 22:16 GMT
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
Jean-Francois Briere - 24 Sep 2006 22:40 GMT
Get rid of String before name between the parenthesises.
Tukewl4u - 25 Sep 2006 01:29 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.