Results 1 to 17 of 17
  1. #1
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Files and "cannot find symbol"

    Hello. I'm reading a tutorial from an on-line text Intro to Programming using Java (David Eck). The exercise asks me to download a .java file (TextIO.java), save it in my working directory, and compile it. So far, so good.

    I then copy a sample of code from the book, give it a name, and save it in my working directory. The sample code calls a method from the TextIO file (userInput = TextIO.getlnInt;).

    Both the sample code and the TextIO file are saved in the same directory. Yet when I compile the sampel code, I get an "cannot find symbol" error, referencing the TextIO.getlnInt line.

    Can anyone explain to me the correct way to get these two programs to work together as they should? Thanks in advance.

    Code of the sample program:
    Java Code:
    public class PrintSquare {
    	public static void main(String[] args) {
    		int userInput;
    		int square;
    
    		System.out.print("Enter a number: ");
    		userInput = TextIO.getlnInt();
    		square = userInput * userInput;
    		System.out.println("The square of your number is: " + square);
    	}
    }

  2. #2
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default Re: Files and "cannot find symbol"

    Is your TextIO.java just saved as another class? Like public class TextIO { ?
    Sincerely, Joshua Green
    Please REP if I help :)

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Files and "cannot find symbol"

    Quote Originally Posted by Humphrey Bogart View Post
    I get an "cannot find symbol" error, referencing the TextIO.getlnInt line.
    What does the message say it cannot find, the class or the method? Make sure you have spelt it correctly.

  4. #4
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Files and "cannot find symbol"

    Hello. Thanks for your response. I'm not sure I know enough about java to answer your question correctly.

    The file I downloaded was a .java file. I compiled it, and the .java file and .class file, all reside in the same folder as the sample code .java and .class files.

    The TextIO code starts public class TextIO, so it is a public class, and the getlnInt method starts public static , so it is a public method.

    Is that what you are asking?

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Files and "cannot find symbol"

    Post the full and exact error message you get.

  6. #6
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default Re: Files and "cannot find symbol"

    You will have to reference the TextIO file in your sample code. Your sample code cannot find the TextIO file because it is in a different class.
    Sincerely, Joshua Green
    Please REP if I help :)

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Files and "cannot find symbol"

    So?

    As long as the other class is in the same package the compiler should find it. If it cannot find the class or the method then the most likely cause is a spelling mistake.

  8. #8
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Files and "cannot find symbol"

    Quote Originally Posted by Junky View Post
    What does the message say it cannot find, the class or the method? Make sure you have spelt it correctly.
    Hello. Yeah, I mis-spell stuff all the time, so the first thing I do when I get an error is to check spelling 3 or 4 times.

    I'm doing this using a command prompt, so the error message shows a "carrot" underneath the TextIO of the userInput = TextIO.getlnInt(); line

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Files and "cannot find symbol"

    SIGH!

    That is not the full and exact error message. If you do not post the full and exact error message I cannot help you.

  10. #10
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Files and "cannot find symbol"

    Quote Originally Posted by Junky View Post
    Post the full and exact error message you get.
    Hello. full error message:
    error: cannot find symbol
    userInput = TextIO.getlnInt();
    ^
    symbol: variable TextIO
    location: class PrintSquare

    I'm guessing java cannot find the TextIO file.

  11. #11
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Files and "cannot find symbol"

    Quote Originally Posted by Humphrey Bogart View Post
    Hello. full error message:
    error: cannot find symbol
    userInput = TextIO.getlnInt();
    ^
    symbol: variable TextIO
    location: class PrintSquare

    I'm guessing java cannot find the TextIO file.
    Hello. The "carrot" goes under the "T" in TextIO.

  12. #12
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Files and "cannot find symbol"

    OK!

    The compiler thinks that TextIO is a variable and not a class. Possible reasons is that despite you claiming you have the TextIO.java class in the same directory you in fact do not. Once again, make sure you have spelt it correctly. Do you have a TextIO.class file? If not try compling TextIO.java first. Also, are you sure the getlnInt method is static and that it is spelt correctly. Lowercase 'l' is usually a cause of such problems

  13. #13
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Files and "cannot find symbol"

    I usually ignore the caret as it is rarely inserted at the correct position.

  14. #14
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Files and "cannot find symbol"

    Hello. Ok, so the TextIO .java. and .class files are both in the same folder as my PrintSquare .java file (PrintSquare has not compiled yet).

    Here is the getlnInt method from the TextIO class
    [CODE]
    public static int getlnInt() {
    int x=getInt();
    emptyBuffer();
    return x;
    }
    [\CODE]

    So I think it is a get(lower case L)nInt, not get(capital i)nInt. Regardless, I get the same error message with both spellings


    Quote Originally Posted by Junky View Post
    OK!

    The compiler thinks that TextIO is a variable and not a class. Possible reasons is that despite you claiming you have the TextIO.java class in the same directory you in fact do not. Once again, make sure you have spelt it correctly. Do you have a TextIO.class file? If not try compling TextIO.java first. Also, are you sure the getlnInt method is static and that it is spelt correctly. Lowercase 'l' is usually a cause of such problems

  15. #15
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Files and "cannot find symbol"

    Are you using an IDE? somethimes they get their panties in a bunch and do not recognise changes. In that case do a clean and build.

    If you are using the command line then delete all the .class files and try compiling again.

    If the two classes are in the same folder and all your spelling is correct then it should compile. Unless you are doing something hinky elsewhere in your code. Can you post the full PrintSquare class. Or if it is too big create a SSCCE.

  16. #16
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Files and "cannot find symbol"

    Hello. I'll try compiling again, and recheck spelling. Very frustrating. I'm using NetBeans to read the TextIO.java file, but I'm (trying to ) compile and run PrintSquare using the command prompt.

    I posted the entire PrintSquare code in the initial post.

    Thanks

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,751
    Rep Power
    19

    Default Re: Files and "cannot find symbol"

    Show us your javac command.
    Do you have a CLASSPATH environment variable declared?
    You shouldn't really, but Quicktime used to have a bad habit of creating one (it may even still do).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Pls solve my "Cannot find symbol" error
    By yvijai in forum New To Java
    Replies: 5
    Last Post: 05-18-2012, 11:17 PM
  2. Strange "Cannot find symbol" error...
    By JimmyD in forum Advanced Java
    Replies: 7
    Last Post: 04-19-2012, 09:37 PM
  3. "Cannot find symbol" errors in Java
    By 23Zone in forum New To Java
    Replies: 1
    Last Post: 02-17-2010, 07:13 AM
  4. Compiling probem "cannot find symbol"
    By thegluups in forum New To Java
    Replies: 27
    Last Post: 01-18-2010, 08:53 PM
  5. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 12:12 AM

Posting Permissions

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