File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Package & Compilation Problem" Watch "Package & Compilation Problem" New topic

Package & Compilation Problem

Moguluri Ravi Kiran
Ranch Hand

Joined: Apr 16, 2010
Posts: 63

this is Kiran and i getting compilation error on packages.

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

& My Classes are

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

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

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

Joined: Oct 27, 2005
Posts: 20271

Moguluri, the problem lies in the way your source files are located. When I put inside folder p1, then run "javac", I get no errors. If I move 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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Package & Compilation Problem
jQuery in Action, 3rd edition