| 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: 819
|
|
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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
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.
|
 |
 |
|
|
subject: cannot find symbol - compiler error?
|
|
|