• 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

cannot find symbol - compiler error?

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a java pgm, "test.java" in "C:\MyProjects\beerV1" folder



and the "BeerExpert.class" file in "C:\MyProjects\beerV1\classes\com\example\model" folder

which contains,

package com.example.model;



so when i try compiling the "test.java" as below i get the, "cannot find symbol" error as below,

C:\MyProjects\beerV1>javac -cp classes test.java
test.java:4: cannot find symbol
symbol : class BeerExpert
location: class test
new BeerExpert();

1 error

can anyone please tell me how to compile the "test.java" file, which uses the "BeerExpert.class" file?
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you just need an import statement

 
Anuradha Prasanna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, Tim McGuire
It is working now ..
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If don't import the class, how java knows where the class situated? public access modifier and import package are two different strories!
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abimaran Kugathasan wrote:If don't import the class, how java knows where the class situated? public access modifier and import package are two different strories!


If you don't import the class, then you'll have to use the fully qualified name of the class everywhere. So test.java would look like
Import is just an easy way of using a class in a package so that you don't have to use the fully qualified name of the class everywhere. The compiler and JVM both look for classes on the classpath...
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit.
 
reply
    Bookmark Topic Watch Topic
  • New Topic