File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes cannot find symbol - compiler error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "cannot find symbol - compiler error?" Watch "cannot find symbol - compiler error?" New topic
Author

cannot find symbol - compiler error?

Anuradha Prasanna
Ranch Hand

Joined: Mar 09, 2006
Posts: 115
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?


SCJP 6.0 90%
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

you just need an import statement

Anuradha Prasanna
Ranch Hand

Joined: Mar 09, 2006
Posts: 115
thanks, Tim McGuire
It is working now ..
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Thanks Ankit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot find symbol - compiler error?
 
Similar Threads
HFSJ- Chap 3
Problem in accessing model in diffeerent package(Servlet-HFS)
Package doesn't exists - error!!- How to resolve?
cannot find symbol - compiler error?
can't import own model