aspose file tools*
The moose likes Beginning Java and the fly likes Cannot Resolve Symbol Error! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot Resolve Symbol Error!" Watch "Cannot Resolve Symbol Error!" New topic

Cannot Resolve Symbol Error!

Prabha Dhandapani
Ranch Hand

Joined: Sep 11, 2003
Posts: 70
Hello everybody,
I have two Java programs in a package.I was able to compile one(A) of the programs but when I tried compiling the other(B) Java Program that creates an instance of A,I get an error, cannot resolve symbol.Below are the Two programs: compiled but when I try compiling, it throws the following error

Can anybody help me with this!It is very urgent!
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Since both classes are in the same package (TestPrograms) you don't have to import the package TestPrograms or any class from TestPrograms package in Remove the import TestPrograms.ThreadTest line from & recompile.

Ever Existing, Ever Conscious, Ever-new Bliss
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Sadanand is correct in saying that the "import TestPrograms.ThreadTest;" is unnecessary (since both classes are in the same package), but that is not the problem. In fact it will compile and run just fine with that statement left in there.
You have a "classpath issue". Remember that packages generally equate to sub-directories. You have a package of "TestPrograms" and a directory of "C:\TestPrograms", which is OK but that means you have to include "C:\" as part of your classpath, explicitly or implicitly.
The quick solution is to cd to "C:\" (root) and run the following:
C:\>javac -classpath "." TestPrograms\*.java
This instructs the "javac" compiler to use the current directory as the classpath, and based on that classpath compile everything in the "TestPrograms" directory that ends with ".java". This will compile. to run it do the following:
C:\>java -cp "." TestPrograms.ThreadCall
Notice that you use "-classpath" for one command and "-cp" for the other. You can circumvent this by setting a CLASSPATH environment value that would be used for every Java command.
This will work whether or not you include the "import TestPrograms.ThreadTest;" in your code.
You might want to think about organizing your Java code that you have a main directory (C:\MyJava, or something like that), and under that you keep your "src\" and "classes\" or "build\" directory for the java source and class files. Then you simply include "C:\MyJava" on your classpath.
It is sorta covered in the JavaRanch Style Guide.
subject: Cannot Resolve Symbol Error!