• Post Reply Bookmark Topic Watch Topic
  • New Topic

package problem  RSS feed

 
Bob Chandler
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys,

got a problem compiling source code that worked perfectly well before I moved all my .java files and .class files into a new folder.

All .java files now include a package statement at the top, I changed directory on the command line ...

Compiler can read the file (Cabin.java), but can't recognise an instance of another class (BookableDate.java) that is created in it.
i.e. Cabin has-a BookableDate

I tried to compile BookableDate, but compiler does not recognise Guest instance within it
i.e. BookableDate has-a Guest

Guest.java does compile.
What's all that about?

Regards
(confused) Bob
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are all these classes in the same package (directory)?

if your classes are in package foo.bar;
and foo is in c:\java then your compile statement would be:

javac -classpath c:\java c:\java\foo\bar\Code.java

with packages, your classpath must include a path to the directory containing the top of the package structure (c:\java in my example)
 
Bob Chandler
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray,

yeah, I checked the classpath issue and I'm thinking that's not the problem - the classes in question are all grouped together in a dir called db which, in turn can be found in my project dir.

The compiler should be able to find all the classes as it comes across references to any one of them.

So, in conclusion:

Cabin class 'has-a' instances of BookableDate - compiler says...
Cannot resolve symbol: class BookableDate

BookableDate class 'has-a' instance of Guest - compiler says...
Cannot resolve symbol: class Guest

Guest has no references to the other classes and compiles fine.

All 3 classes live in c:\project\db\[classname]

It's the simple things that get me!
Regards
Bob (a bit fed up as it goes) Chandler
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's you CLASSPATH set to, and what are the package names used at the top of the file? If you provide that information, we will be more able to help.


Thanks,
 
Peter Shipway
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set path=C:\j2sdk1.4.2_03\bin;%path%
set classpath=H:\Programming 1\Java Files\TerminalIO.jar;H:\Programming 1\Java Files\BreezySwing.jar;C:\Program Files\j2sdk_nb\j2sdk1.4.2\jre\lib\ext;%classpath%
set classpath=.;%classpath%

Is the .bat file i am using for classpath since im at uni and the computers use deepfreeze here, i dont have ANY packages at the top. None I am very lost. I have looked at the API and cant tell which package the Character class is in.
 
Bob Chandler
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Joel,

statement at the top of each src file is:
package project.db;

oh my God!....lightbulb moment!

I just changed the package statement to:
package db;
and everything now compiles

What was I thinking?
Cheers Joel and Ray - now I can get some work done, yay!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!