• 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

Package & Compilation Problem

 
Ranch Hand
Posts: 63
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?



 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic