File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Package & Compilation Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Package & Compilation Problem" Watch "Package & Compilation Problem" New topic
Author

Package & Compilation Problem

Moguluri Ravi Kiran
Ranch Hand

Joined: Apr 16, 2010
Posts: 62

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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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.

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Package & Compilation Problem
 
Similar Threads
Access Specifier
error while compiling
PACKAGES
Creating an instance of a sub-class runs parent and child constructors?
Confusion Question