Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: cannot find symbol error

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Location
    Cedar Rapids,Iowa
    Posts
    12
    My Mood
    Sick
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default This problem has been resolved.

    Hi, I am new to java this semester and I am getting a cannot find symbol error(calculateCentimeters,calculateFeet,calculate Yards). I am struggling to fix this, any advice would help. It is the system.out.println lines that are wrong and I must have a return in this program. Thank you.

    class inchesProgram{
     
        public static void main (String args[]){
     
            double inches = 1000.0;
     
    	ItoC(inches);// method call //
    	ItoF(inches);// method call //
    	ItoY(inches);// method call //
     
    	System.out.println("This is centimeters for 1000 inches: "+calculateCentimeters);
    	System.out.println("This is feet for 1000 inches: "+calculateFeet);
    	System.out.println("This is yards for 1000 inches: "+calculateYards);
    	}
     
        static double ItoC(double inches){
    		double calculateCentimeters;
    		calculateCentimeters = inches*2.54;
    		return calculateCentimeters;
    	}
     
        static double ItoF(double inches){
    		double calculateFeet;
    		calculateFeet = inches/12;
    		return calculateFeet;
    	}
     
        static double ItoY(double inches){
    		double calculateYards;
    		calculateYards = inches/36;
    		return calculateYards;
    	}
    }
    Last edited by Topflyt; November 5th, 2011 at 09:02 AM. Reason: issue resolved


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: cannot find symbol error

    When declaring a variable, you have to give it a type. I can't just say:

    x = 7;

    I have to tell Java what the heck x is:

    int x = 7;

    Same with Strings, Objects, doubles, whatever.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Location
    Cedar Rapids,Iowa
    Posts
    12
    My Mood
    Sick
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: cannot find symbol error

    where do I declare(what lines), didn't I declare the variables in lines 17,23,29?(double calculateCentimeters, double calculateFeet, double calculateYards)?

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: cannot find symbol error

    Quote Originally Posted by Topflyt View Post

    Your problem is here, you cannot access variables that are only defined in methods. You have to call the method:

    e.g. System.out.println("This is centimeters for 1000 inches: " +ItoC(1000) );

    System.out.println("This is centimeters for 1000 inches: "+calculateCentimeters);
    System.out.println("This is feet for 1000 inches: "+calculateFeet);
    System.out.println("This is yards for 1000 inches: "+calculateYards);
    }

    static double ItoC(double inches){
    double calculateCentimeters;
    calculateCentimeters = inches*2.54;
    return calculateCentimeters;
    }

    static double ItoF(double inches){
    double calculateFeet;
    calculateFeet = inches/12;
    return calculateFeet;
    }

    static double ItoY(double inches){
    double calculateYards;
    calculateYards = inches/36;
    return calculateYards;
    }
    }

    Try that and see if it works.

  5. The Following User Says Thank You to mccolem For This Useful Post:

    Topflyt (November 4th, 2011)

  6. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: cannot find symbol error

    mccolem, please read this before posting again: http://www.javaprogrammingforums.com...n-feeding.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: cannot find symbol error

    Quote Originally Posted by Topflyt View Post
    where do I declare(what lines), didn't I declare the variables in lines 17,23,29?(double calculateCentimeters, double calculateFeet, double calculateYards)?
    Yes, but you declared them inside the method, which means they're only available inside the method. Hint- You're returning a value from those methods, but you aren't doing anything with those values.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #7
    Junior Member
    Join Date
    Nov 2011
    Location
    Cedar Rapids,Iowa
    Posts
    12
    My Mood
    Sick
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: cannot find symbol error

    @mccolem Thank you, that worked. I guess i got stuck when changing a void method with a return method. When I made the public static void method it printed just as I had it in the above program, not really sure why it has to change in the return version but than you anyway.

  9. #8
    Junior Member
    Join Date
    Nov 2011
    Location
    Cedar Rapids,Iowa
    Posts
    12
    My Mood
    Sick
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: cannot find symbol error

    OK, Thank you to all who responded, much love.

  10. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: cannot find symbol error

    Those methods should almost definitely not be void.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #10
    Junior Member
    Join Date
    Nov 2011
    Location
    Cedar Rapids,Iowa
    Posts
    12
    My Mood
    Sick
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: cannot find symbol error

    Thank you Kevin, I was able to get it right. I was using void methods before and what I had worked for void methods, I was stuck when I had to make a return method.

Similar Threads

  1. Cannot find symbol ERROR
    By yacek in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 21st, 2011, 11:39 PM
  2. error :cannot find symbol
    By iswan in forum AWT / Java Swing
    Replies: 1
    Last Post: October 1st, 2011, 08:26 AM
  3. NEW TO PROGRAMMING, PLEASE HELP (cannot find symbol error)
    By bluescholar in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 26th, 2011, 04:48 PM
  4. Cannot find symbol error
    By AnuR in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 23rd, 2011, 02:50 PM
  5. cannot find symbol Error
    By bananasplitkids in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 9th, 2010, 02:36 AM