This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Compiler Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiler Error" Watch "Compiler Error" New topic
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: 18541
    
    8

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Compiler Error
 
Similar Threads
Need help with Car Inventory Program part 3
readLine() problem
the get() line...
accessing a "main" variable from within a class method
Based on the message, what kind of failure is this?