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:
ThreadTest.java compiled but when I try compiling ThreadCall.java, it throws the following error
Can anybody help me with this!It is very urgent! Thanks, Prabha
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 ThreadCall.java. Remove the import TestPrograms.ThreadTest line from ThreadCall.java & recompile.
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.