jQuery in Action, 3rd edition
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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compile error." Watch "Compile error." New topic

Compile error.

Pranav Gangani

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

Joined: Oct 13, 2005
Posts: 44442
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

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

Joined: Oct 13, 2005
Posts: 44442
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."
    I agree. Here's the link: http://aspose.com/file-tools
    subject: Compile error.
    It's not a secret anymore!