Results 1 to 3 of 3
- 01-23-2010, 05:45 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
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...
The compiler error is: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
GradeBookTest.java:24: displayMessage() in GradeBook cannot be applied to (java.lang.String)
myGradeBook.displayMessage( nameOfCourse );
^
1 error
Here's the code for GradeBook:
For what it's worth GradeBook compiles w/o issue.Java Code:public class GradeBook { public void displayMessage() { System.out.println( "Welcome to the Grade Book!"); } }
Thanks for the help!Last edited by bottlecap; 01-23-2010 at 05:58 AM.
-
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?
-
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
-
Simple "if" statement problem....compiling error.
By CYANiDE in forum New To JavaReplies: 4Last Post: 10-14-2009, 09:56 PM -
Having error while compiling
By Kodeee in forum New To JavaReplies: 12Last Post: 03-17-2009, 11:08 AM -
Compiling error
By lawksalih in forum New To JavaReplies: 6Last Post: 01-29-2008, 07:26 PM -
Error during compiling
By boy22 in forum New To JavaReplies: 2Last Post: 08-03-2007, 02:42 AM -
Error while compiling
By ai_2007 in forum Advanced JavaReplies: 1Last Post: 07-01-2007, 11:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks