• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiling via Command prompt.  RSS feed

 
Bharadwaj Adepu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • 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();
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!