Results 1 to 17 of 17
Thread: Files and "cannot find symbol"
- 10-16-2012, 02:44 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 88
- Rep Power
- 0
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); } }
- 10-16-2012, 02:51 AM #2
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 :)
- 10-16-2012, 03:13 AM #3
- 10-16-2012, 03:15 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 88
- Rep Power
- 0
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?
- 10-16-2012, 03:17 AM #5
Re: Files and "cannot find symbol"
Post the full and exact error message you get.
- 10-16-2012, 03:19 AM #6
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 :)
- 10-16-2012, 03:20 AM #7
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.
- 10-16-2012, 03:20 AM #8
Member
- Join Date
- Mar 2011
- Posts
- 88
- Rep Power
- 0
Re: Files and "cannot find symbol"
- 10-16-2012, 03:23 AM #9
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-16-2012, 03:23 AM #10
Member
- Join Date
- Mar 2011
- Posts
- 88
- Rep Power
- 0
- 10-16-2012, 03:25 AM #11
Member
- Join Date
- Mar 2011
- Posts
- 88
- Rep Power
- 0
- 10-16-2012, 03:28 AM #12
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
- 10-16-2012, 03:29 AM #13
Re: Files and "cannot find symbol"
I usually ignore the caret as it is rarely inserted at the correct position.
- 10-16-2012, 03:41 AM #14
Member
- Join Date
- Mar 2011
- Posts
- 88
- Rep Power
- 0
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
- 10-16-2012, 03:49 AM #15
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.
- 10-16-2012, 04:03 AM #16
Member
- Join Date
- Mar 2011
- Posts
- 88
- Rep Power
- 0
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
- 10-16-2012, 10:02 AM #17
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Pls solve my "Cannot find symbol" error
By yvijai in forum New To JavaReplies: 5Last Post: 05-18-2012, 11:17 PM -
Strange "Cannot find symbol" error...
By JimmyD in forum Advanced JavaReplies: 7Last Post: 04-19-2012, 09:37 PM -
"Cannot find symbol" errors in Java
By 23Zone in forum New To JavaReplies: 1Last Post: 02-17-2010, 07:13 AM -
Compiling probem "cannot find symbol"
By thegluups in forum New To JavaReplies: 27Last Post: 01-18-2010, 08:53 PM -
"Cannont find symbol Constructor" error
By Welsh in forum New To JavaReplies: 7Last Post: 01-25-2008, 12:12 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks