Results 1 to 3 of 3
  1. #1
    bottlecap is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default compiling error should be a simple fix.

    I'm using the Deitel Java how to program 7th edition and am totally stuck on this 1 error. It's really bugging me, I'm usually able to figure out the error on my own, but can't in this case...

    Java Code:
    import java.util.Scanner; // imports Scanner
    
    public class GradeBookTest
    {
    	// main method begins program execution
    	public static void main( String args[] )
    	{
    		// create Scanner to obtain input
    		Scanner input = new Scanner( System.in );
    		
    		// create a GradeBook object and assign it to myGradeBook
    		GradeBook myGradeBook = new GradeBook();
    		
    		// prompt for and input course name
    		System.out.println( "Please enter the course name:" );
    		String nameOfCourse = input.nextLine(); // read a line of text
    		System.out.println(); // outputs a blank line
    		
    		// call myGradeBooks displayMessage method
    		// and pass nameOfCourse as an argument.
    		myGradeBook.displayMessage( nameOfCourse ); *** error **
    		} // end main
    
    } // end class GradeBook Test
    The compiler error is:

    GradeBookTest.java:24: displayMessage() in GradeBook cannot be applied to (java.lang.String)
    myGradeBook.displayMessage( nameOfCourse );
    ^
    1 error


    Here's the code for GradeBook:

    Java Code:
    public class GradeBook
    {
    	public void displayMessage()
    	{
    		System.out.println( "Welcome to the Grade Book!");
    	}
    }
    For what it's worth GradeBook compiles w/o issue.


    Thanks for the help!
    Last edited by bottlecap; 01-23-2010 at 06:58 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The problem as I see it is that GradeBook has a displayMessage() method, but not a displayMessage method that takes a String as a parameter.

    For a more helpful reply though, you'll need to post the code of the GradeBook class, no?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    OK, I'm right: you're calling displayMessage by passing a String parameter:
    Java Code:
    myGradeBook.displayMessage( nameOfCourse ); // nameOfCourse is the String parameter

    Your displayMessage method as written accepts no parameters:
    Java Code:
    	public void displayMessage() // *** this method accepts no parameters
    	{
    		System.out.println( "Welcome to the Grade Book!");
    	}

    The solution: either call the method without a parameter, or create an overload that accepts a String parameter.

Similar Threads

  1. Simple "if" statement problem....compiling error.
    By CYANiDE in forum New To Java
    Replies: 4
    Last Post: 10-14-2009, 10:56 PM
  2. Having error while compiling
    By Kodeee in forum New To Java
    Replies: 12
    Last Post: 03-17-2009, 12:08 PM
  3. Compiling error
    By lawksalih in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 08:26 PM
  4. Error during compiling
    By boy22 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 03:42 AM
  5. Error while compiling
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2007, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •