• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compiler Error

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, post your complete code.
I think, it will help to analyse the problem.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was my problem, I didn't include the import java.io.* in the code.

Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic