This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Compile error. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compile error." Watch "Compile error." New topic
Author

Compile error.

Pranav Gangani
Greenhorn

Joined: Jul 08, 2008
Posts: 5
Hi. I am getting a compile error in class B.
I am using a normal import and then too I am getting an error even for this small piece of code.
But when I import java api classes it compiles fine.
I am using EditPlus v2.11
Would you PLEASE help me out ASAP.


//Class A



//Class B


---------- Compile ----------
B.java:1: '.' expected
import A;
^
1 error

Output completed (0 sec consumed) - Normal Termination
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37945
    
  22
You can't import a class which hasn't got a package declaration. The two classes are in the same package anyway, so you don't need an import statement.

And please read this FAQ.
Pranav Gangani
Greenhorn

Joined: Jul 08, 2008
Posts: 5
But what about this. I have two classes .
My BeerSelect class is in C:\MyProjects\beerV1\src\com\example\web.
Whereas BeerExpert class is in C:\MyProjects\beerV1\src\com\example\model.
Then too I get the same import error when I import BeerExpert in BeerSelect.
Compiler says "no such directory exists".


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37945
    
  22
Totally different situation. You haven't posted real code, not have you told the details of your actual problem.

Is that an example from the Head First Book? I don't actually have a copy myself.

If you go through BeerSelect, you see it has a dependency on BeerExpert.
You need to compile the classes in com.example.model before you try compiling the classes in com.example.web.

Easiest way to do it:
  • Make sure you have the javax.servlet.http package installed; it is in J2EE not J2SE
  • Empty your folder of everything except the Java source files. No subfolders left.
  • Compile the dependency (BeerExpert) from the folder like this: javac -d . BeerExpert.java
  • Compile the client (BeerSelect) from the same folder like this: javac -d . BeerSelect.java
  • The "-d" bit means "create directory" and the "." bit means "start in the current directory."
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Compile error.
     
    Similar Threads
    SQL connection error
    Help on Packages!!
    what this mean?
    interface error
    Problem with protected variable...