Java import/see classes / compile problems

calhoun

Gawd
Joined
Jan 20, 2003
Messages
608
Im trying to test a class to ensure it works but I cant get it to compile because it cant find it:

Code:
D:\Documents and Settings\Administrator\My Documents\java\calculator>javac -clas
spath "D:\Documents and Settings\Administrator\My Documents\java\calculator" Bra
inTest.java -verbose
[parsing started BrainTest.java]
BrainTest.java:11: <identifier> expected
import .CalcBrain;
       ^
BrainTest.java:11: '.' expected
import .CalcBrain;
                 ^
[parsing completed 80ms]
[total 160ms]
2 errors
or
Code:
D:\Documents and Settings\Administrator\My Documents\java\calculator>javac -clas
spath "D:\Documents and Settings\Administrator\My Documents\java\calculator" Bra
inTest.java -verbose
[parsing started BrainTest.java]
[parsing completed 80ms]
BrainTest.java:11: cannot resolve symbol
symbol  : class CalcBrain
location: package calculator
import calculator.CalcBrain;
                  ^
[loading c:\programming\javasdk1.4.3\j2sdk1.4.2\jre\lib\rt.jar(java/lang/Object.
class)]
[loading c:\programming\javasdk1.4.3\j2sdk1.4.2\jre\lib\rt.jar(java/lang/String.
class)]
[checking calculator.Braintest]
BrainTest.java:18: cannot resolve symbol
symbol  : class CalcBrain
location: class calculator.Braintest
    CalcBrain cbrain = new CalcBrain();
    ^
BrainTest.java:18: cannot resolve symbol
symbol  : class CalcBrain
location: class calculator.Braintest
    CalcBrain cbrain = new CalcBrain();
                           ^
[total 460ms]
3 errors

the CalcBrain.java class compiles satisfactory.
CalcBrain.java and CalcBrain.class as well as Braintest.class reside in the directory where Im attempting to make this work.


If I run them via JDeveloper they work, but its for an assignment to make a Calculator (duh),and it stipulates we've to use TextPad other wise I would've used JDeveloper :)

Any clues would be appreciated :)
 
I'm rusty at Java (because using it was such a PITA that I never bothered with it after the classes that required the use of it) but I recall getting crap like that as well, though not necessarily what exactly the problem/solution was...

Is CalcBrain actually packaged in the "calculator" package?

I can poke through my saved school work when I get home if you don't get it figured out or resolved by someone else...
 
I have
Code:
package calculator;
in both files, so unless theres something more to packaging it up It is
 
Yes.

Ive tried it in the Default Location, same problem, Tried it after explicitly setting with set CLASSPATH=blah tried it with it set elsewhere and hopeing for the best but no matter what Class path is set to it doesnt help :(
 
you have your package 'calculator'. this has to be in its own subdirectory, it looks like you know that already. your main program has to be in the directory above it though, i guess 'your docs\java'. you should not need to specify the classpath since you're compiling from within that directory. to summarize
Code:
my documents\java
|---calculator
|   |
|   \---CalcBrain.java
|
\---YourMainProgram.java (BrainTest.java ?)
also, you only want the 'package calculator;' line in CalcBrain.java. then in BrainTest.java, the 'import calculator.CalcBrain;'

our professor was trying to teach us to make packages so as a requirement for one program, we had to move a class we made for the previous program into a package. the idea was to use a binary file generated from the previous program, where the class was not in the package, in the current program. it didn't work though because java saw the class in the package in a different way from when it was just in the same directory. took a while for him to figure it out.
 
Well thats made some progress. If I have the Braintest.java source up a level with package calculator; in it, then it will compile, but I have to move the Braintest.class file back into the calculator directory to run it ...... but at least it works :D

Thanks :)
 
Back
Top