• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error: Cannot find symbol during Importing package

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:


 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies ... i was confuse with the CLASSPATH ...i hope it will work now
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kan tao wrote:Thanks . . . i hope it will work now

You're welcome . . . have you tried it?
reply
    Bookmark Topic Watch Topic
  • New Topic