• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compile error.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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."
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic