| Author |
Compiler Error
|
Jan Coff
Greenhorn
Joined: Dec 04, 2005
Posts: 5
|
|
I'm trying to compile a sample Dates class and am getting the following compile errors: Dates.java: 57 cannot find symbol symbol: class BufferedReader location: class Dates BufferedReader stdin = new BufferedReader ( new InputStreamReader(System.in)) Any ideas why the compiler can't find this?
|
 |
Sowjanya Chowdary
Ranch Hand
Joined: Aug 22, 2005
Posts: 35
|
|
Please, post your complete code. I think, it will help to analyse the problem.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
For most of the classes in the standard Java API that you use, you have to explicitly import them into your code. "Import" means telling the compiler what package they are in. So for BufferedReader, whose full name is "java.io.BufferedReader" because it's in the java.io package, you have to do this at the top of your class:Then the compiler will be able to tell that your "BufferedReader" class is actually the "java.io.BufferedReader" and not, for example, the "com.walmart.BufferedReader" class. If typing all the required import statements gets to be too tedious, you can import an entire package at once, like this:This tells the compiler that you might use anything from the java.io package, so it should look in that package when trying to find classes. However, the java.lang package is automatically imported into every class, so you don't have to do that. So you can use String without having to bother to import java.lang.String, for example.
|
 |
Jan Coff
Greenhorn
Joined: Dec 04, 2005
Posts: 5
|
|
Originally posted by Paul Clapham: For most of the classes in the standard Java API that you use, you have to explicitly import them into your code. "Import" means telling the compiler what package they are in. So for BufferedReader, whose full name is "java.io.BufferedReader" because it's in the java.io package, you have to do this at the top of your class: Then the compiler will be able to tell that your "BufferedReader" class is actually the "java.io.BufferedReader" and not, for example, the "com.walmart.BufferedReader" class. If typing all the required import statements gets to be too tedious, you can import an entire package at once, like this: This tells the compiler that you might use anything from the java.io package, so it should look in that package when trying to find classes. However, the java.lang package is automatically imported into every class, so you don't have to do that. So you can use String without having to bother to import java.lang.String, for example.
|
 |
Jan Coff
Greenhorn
Joined: Dec 04, 2005
Posts: 5
|
|
That was my problem, I didn't include the import java.io.* in the code. Thanks
|
 |
 |
|
|
subject: Compiler Error
|
|
|