• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile error.

 
Pranav Gangani
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic