Import Error??

S

Samuel T

Hi,

Can you guys help me out with this? I was trying to use a method found
in a class that is in another folder. An error came up that said:

E:\Java\Black Object Orientated Book\Chapter 3\ShipMain1.java:7:
cannot access Packages.Ships.Ship
bad class file: .\Packages\Ships\Ship.class
class file contains wrong class: Ship
Please remove or make sure it appears in the correct subdirectory of
the classpath.
Ship argo;

Any ideas what to do?

Thanks in advance,

Samuel T
 
K

KC Wong

Can you guys help me out with this? I was trying to use a method found
in a class that is in another folder. An error came up that said:

E:\Java\Black Object Orientated Book\Chapter 3\ShipMain1.java:7:
cannot access Packages.Ships.Ship
bad class file: .\Packages\Ships\Ship.class
class file contains wrong class: Ship
Please remove or make sure it appears in the correct subdirectory of
the classpath.
Ship argo;

Any ideas what to do?

Move the source code away from the class file... I think you have Ship.java
and Ship.class in the same directory. This will confuse the compiler in some
situations - it is taking the source code as a class.

An eaiser way is to organize your files in a different way - don't mix
source and class. Put all the source code in a directory (e.g. src) and
maintain the package structure inside it, and compile them with the "-d"
option to specify another directory (e.g. bin) to store the class files.
 
B

Babu Kalakrishnan

Samuel said:
Hi,

Can you guys help me out with this? I was trying to use a method found
in a class that is in another folder. An error came up that said:

E:\Java\Black Object Orientated Book\Chapter 3\ShipMain1.java:7:
cannot access Packages.Ships.Ship
bad class file: .\Packages\Ships\Ship.class
class file contains wrong class: Ship
Please remove or make sure it appears in the correct subdirectory of
the classpath.
Ship argo;

Any ideas what to do?

What package is the class Ship declared to be in ? With your directory
structure, the class should have a "package" declaration with
"Packages.Ships" as the package name. If anything else (or if there is
no package declaration), it will not be acceptable to the classloader.

BTW, As per Sun's suggested naming convention, package names normally
start with a small letter.

BK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top