• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package & Compilation Problem

 
Moguluri Ravi Kiran
Ranch Hand
Posts: 63
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
this is Kiran and i getting compilation error on packages.

MyDir
| - Class1.java
| - Class2.java
| - p1(package dir)
----------> | - Class1.class (it is generated successfully)
| - Class2.class (error while compiling this)

& My Classes are




Now when ever i remove the "Class1.java" from the MyDir ---- there is no error. & successful compilation,running.
when ever i place the "Class1.java" in the MyDir ---- error appears......... what is the reason for this ?



 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://forums.sun.com/thread.jspa?threadID=644158

In short, when you use "import p1.*", the compiler looks for the "Class1" and find it the current dir. In order to explicitly tell the compiler to look for the dir "p1" either you have to use the full reference, like "p1.Class1" OR mention it on CP. But when you delete the java file then it looks for the "p1" dir.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moguluri, the problem lies in the way your source files are located. When I put Class1.java inside folder p1, then run "javac Class2.java", I get no errors. If I move Class1.java to the root folder and remove folder p1 I also get an error. Try always using the package structure for your source files as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic