Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# Error: Cannot find symbol during Importing package

kan tao
Greenhorn
Posts: 9
How can i solved the compile error: Cannot find symbol for the following codes

symbol: class test2
location: test.test3
test2 aa = new test2();

I'm trying to instantiate test2.java in test3.java

Both the files are in C:\MyJavaProg\test

My java path is set to C:\Program Files\Java\jdk1.6.0_06

test2 code:

test3 code:

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15279
39
You don't need to import test.*; in test3.java, because class test3 is already in the package test.

It should be able to find class test2, but you need to set the classpath correctly when you compile and run the program. Set the classpath by using the -cp option on the command line. The classpath should include the base directory of the package (in this case: C:\MyJavaProg). Example:

javac -cp C:\MyJavaProg C:\MyJavaProg\test3.java

java -cp C:\MyJavaProg test.test3

My java path is set to C:\Program Files\Java\jdk1.6.0_06

I don't know what you mean with "java path" (do you mean PATH or CLASSPATH?), but you should not set the classpath to the JDK installation directory. It's better to not set the CLASSPATH environment variable at all. Make sure that the bin directory of your JDK (C:\Program Files\Java\jdk1.6.0_06\bin) is added to the PATH. Step 4 of the JDK installation instructions explains how to do that.

Campbell Ritchie
Sheriff
Posts: 48943
60
You have obviously set your PATH environment variable correctly, but as Jesper says, you ought not to set a CLASSPATH at all if you can help it.
Try compiling the test2 class first.

kan tao
Greenhorn
Posts: 9
Thanks for the replies ... i was confuse with the CLASSPATH ...i hope it will work now

Campbell Ritchie
Sheriff
Posts: 48943
60
kan tao wrote:Thanks . . . i hope it will work now
You're welcome . . . have you tried it?