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

    Default Cannot find Symbol error - mystery problem

    Hello. I wrote about this problem a couple of days ago. I cannot fix it, so I'm re-posting the question.

    I am going through an online text (Introduction to Programming In Java, 6th Ed., David Eck) and trying to complete an exercise in the text. The instructions are to download an already written file TextIO.java and compile it and save it. The class compiles correctly and I save TextIO.java and TextIO.class in the same folder on my C: drive. The exercise then has me write a small program (PrintSquare), compile it, and run it. The program calls a method in the TextIO class. I write the PrintSquare program, save it as a .java file in the same folder as the TextIo.class file.

    So TextIO.java, TextIO.class, and PrintSquare.java all reside in the same folder on my c: drive. When I try and compile PrintSquare, I get a "cannot find symbol" error.

    I have gone through the process of downloading and recompiling TextIO multiple times. I have re-written PrintSquare multiple times. I have checked and triple checked for spelling errors. Yet, I still get the "cannot find symbol" error when compiling PrintSquare.

    I am usng a command prompt for compiling.

    Can anyone tell me why the compiler cannot find TextIO? Thanks in advance.

    The PrintSquare code:
    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.print("Your number squared is " + square);
    	}
    }
    The error message:
    Cannot find symbol
    userInput = TextIO.getlnInt();
    symbol variable; TextIO
    location class: PrintSquare

    The TextIO class
    Java Code:
    public class TextIO {
    //snip
    //snip
    
    /**
        * Skips whitespace characters and then reads a value of type int from input, discarding the rest of 
        * the current line of input (including the next end-of-line character, if any).  When using standard IO,
        * this will not produce an error; the user will be prompted repeatedly for input until a legal value
        * is input.  In other cases, an IllegalArgumentException will be thrown if a legal value is not found.
        */
       public static int getlnInt() { 
          int x=getInt(); 
          emptyBuffer(); 
          return x; 
       }
    //snip
    //snip
    }

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

    Default Re: Cannot find Symbol error - mystery problem

    Hello. Aha - I fixed it!

    To compile PringtSquare, I typed the following at the command prompt:
    javac -classpath . PrintSquare.java

    PrintSquare then compiled successfully and I was able to run it successfully. Yeah!

    So does this mean there is a problem with my CLASSPATH variable? Currently, this is what is in my CLASSPATH variable:
    C:\Program Files (x86)\Java\jdk1.7.0_2\lib\tools.jar;

    My working directory is C:/Desktop/Java (where TextIO and PrintSquare files reside and to where I navigate the command prompt when compiling and running)

Similar Threads

  1. Cannot find symbol error
    By abdulahadone in forum New To Java
    Replies: 11
    Last Post: 03-23-2012, 12:45 PM
  2. Cannot find symbol Error
    By new_Java in forum New To Java
    Replies: 3
    Last Post: 02-18-2011, 12:23 AM
  3. error cannot find symbol
    By jcoon3 in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 11:56 PM
  4. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  5. 'Cannot find symbol' error
    By minihazard10 in forum New To Java
    Replies: 6
    Last Post: 10-10-2008, 05:05 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
  •