• 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

Compiling via Command prompt.

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam calling a method of class Test1 in class Test2 by creating the instance of the Test1, Ive compiled class Test1 it compiled fine but when i try to compile class Test2 its giving error

Test2.java:8: cannot find symbol
symbol : class Test1
location: class pack.Test2
Test1 t1= new Test1();

Both the classes are in the same package called pack

The matter is this is compiling fine in eclipse editor but failing in command prompt why?? how could this be resolved?

Test2.java:8: cannot find symbol
symbol : class Test1
location: class pack.Test2
Test1 t1= new Test1();
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java classes are identified by their qualified names. If a class is in a named package, its qualified name is myPackage.MyClass.

So you will not find a class called "Test1" in the "pack" directory. Instead, you will find pack.Test1 in the directory that is the parent of "pack."

Unless you specify a classpath, Java's default is to look for classes in the current directory. So...

You want to set the current directory to the parent of "pack." Then compile with...

javac pack/Test2.java

That way, when Java looks in the current directory (the parent of "pack") for the class pack.Test1, it will find it.

If Java still can't find Test1, then you have probably set a system classpath that does not include a dot (.) for the current directory. In that case, try using the classpath flag to specify the current directory...

javac -cp . pack/Test2.java

Note the spaces before and after the dot. If this works, but it did not work without the "-cp . " then you should add a dot to your system classpath.
 
reply
    Bookmark Topic Watch Topic
  • New Topic