• Post Reply Bookmark Topic Watch Topic
  • New Topic

Complling with packages  RSS feed

 
shambhavi sivan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all !

i have the following 2 java classes :



and



when i compile the circle class as:   F:\Shambhavi\SHAMBHAVI>javac -d G: PROJECT/circle.java 
there is no problem and i have the respective and packages and class file created in the G drive .

but next when i compile the sample class as:   F:\Shambhavi\SHAMBHAVI>javac -d . -cp G: sample.java
i get these 2 errors
sample.java:2: error: cannot find symbol
import test.pcks.sample.circle;
                       ^
  symbol:   class circle
  location: class sample
sample.java:9: error: cannot find symbol
circle.main(a);
^
  symbol:   variable circle
  location: class sample
2 errors

when they belong to different directories , then why this error ?


if i put the circle class in a package test.pcks instead , and change the import statement accordingly in the sample class, i  dont get such an error and the program runs fine with the output generated !

can somebody explain what exactly is happening here
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can say circle s = new circle();
and then you call the methods.

 
shambhavi sivan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
uh no ,  circle is not found here .....

so i don't think your solution will help ..... thanks anyways

anybody else who could help me on this ??
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shambhavi sivan wrote:


when i compile the circle class as:   F:\Shambhavi\SHAMBHAVI>javac -d G: PROJECT/circle.java 
there is no problem and i have the respective and packages and class file created in the G drive .


First, you do know that you are not exactly following the correct practice in organizing your files right?


Two points. One. The circle.java file should be in the "test/pcks/sample" directory from the classpath root. And two. The classpath should point to the root -- and in this case, I am assuming it is "F:\Shambhavi\SHAMBHAVI\PROJECT".

So... The file should be the "F:\Shambhavi\SHAMBHAVI\PROJECT\test\pcks\sample\circle.java" file. And the command to compile should be  (assuming the same directory as above)...

F:\Shambhavi\SHAMBHAVI>  javac -cp  PROJECT   PROJECT\test\pcks\sample\circle.java



So... Can you get it to work? Probably, but since you are not following the correct/common practice, there isn't going to be many here that can help you out.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!