Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie! Compiling w/ multiple classes?

Status
Not open for further replies.

bac37

IS-IT--Management
Mar 16, 2002
3
US
I am very new to Java. What I am having trouble with is when I try to compile a .java file that calls out other class files I always get "cannot resolve symbol" error pointing to the name of the class. The class.java files compile fine. Any help appreciated. [sadeyes]

Thanks
 
First, I would rename class.java and the Class class that it must contain. I hope you just used the name "class" as an example when posting...

To compile multiple classes, the easiest way is to start at the bottom of the dependencies and compile there, than back up the list. For example, if CashRegister.java uses Prices.java which uses InventoryItem.java, then first compile InventoryItem, then Prices, then CashRegister.
 
I believe if you compile the class it will compile all dependent classes before finally compiling the class. --Derek

"Fear not the storm for this is where we grow strong."
 
Maybe I asked the question wrong. I created an applet that creates an instance of a class. The class compiles fine however the applet will not compile. Gives the error in my previous post. Thanks for all replies thus far.
 
Did you make sure to include the
Code:
import
statement? The error is coming from the fact that the compiler doesn't recognize the symbol (most likely the class name) in the declaration of the instance.
If you have a snippet of code that would help. --Derek

"Fear not the storm for this is where we grow strong."
 
First off, specifying the classpath with the environment variable or program switch
Code:
 java -cp .;sourceDir;otherDir ...
will almost certainly solve the problem. However, if you still encounter problems, there are two more things to try.
1. If you are using packages, make sure your source files are in the right directories.
2. Even if the classpath is correctly set, it still might not be able to link the files. I encountered this only once on a friends computer and got around it by using *.java instead of individual source files (this complicates debugging since there is a potential for many more errors and the screen buffer is only so big...)
 
Thanks for all the replies! All suggestions were helpful. The CLASSPATH was the issue. I did not have the directory that contained the files in the path. I had read somewhere that the path ended 1 level above this directory. Thanks again. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top