wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Frustrating compilation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Frustrating compilation "Cannot resolve symbol" error" Watch "Frustrating compilation "Cannot resolve symbol" error" New topic
Author

Frustrating compilation "Cannot resolve symbol" error

Manavendra Chimakurthi
Greenhorn

Joined: Sep 04, 2003
Posts: 3
Hello everyone. I have gone through a bunch of classpath related messages before posting this. I appreciate your help in this very much.
Here are two classes I have:
class FooBar
{
   public String toString(){
   return new String("FooBar lives");
   }
}
class Foo
{
   public static void main(String args[]){
      System.out.println("Foo lives");
      FooBar foobar = new FooBar();
      System.out.println(foobar);
   }
}
If I have both classes in the same file. I can compile Foo.java (javac Foo.java) and run Foo (java Foo) with expected results:
Foo lives
FooBar lives
If I have each class in its own file. I can compile FooBar (javac FooBar.java), but when I try to compile Foo (javac Foo.java), I get a "Cannot resolve symbol" error for the FooBar class.
Here is the error transcript:
Foo.java:5: cannot resolve symbol
symbol: class FooBar
location: class Foo
FooBar foobar = new FooBar();
^
Foo.java:5: cannot resolve symbol
symbol: class FooBar
location: class Foo
FooBar foobar = new FooBar()
                             ^
2 errors

I don't understand where the problem is. Classes in the current directory are available without having to set the classpath explicitly - right. I ran javac using the -classpath option but still got the same error. Here are my environment variable settings:
CLASSPATH: C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar;C:\Program Files\junit3.8.1\junit.jar;C:\Program Files\junit3.8.1;
JAVA_HOME: C:\Program Files\j2sdk_nb\j2sdk1.4.2
PATH: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\PROGRA~1\Tcl\bin;C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin;C:\Program Files\Apache Group\apache-ant-1.5.4\bin;
[ September 04, 2003: Message edited by: Manavendra Chimakurthi ]
[ September 04, 2003: Message edited by: Manavendra Chimakurthi ]
[ September 04, 2003: Message edited by: Manavendra Chimakurthi ]
[ September 04, 2003: Message edited by: Manavendra Chimakurthi ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

By default current directory is included in the classpath.
Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.
You have overriden the default classpath, so use
SET CLASSPATH=%CLASSPATH%;.


[ September 04, 2003: Message edited by: Pradeep Bhat ]

Groovy
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
You need to add the current directory (.) to the classpath:
CLASSPATH: C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar;C:\Program Files\junit3.8.1\junit.jar;C:\Program Files\junit3.8.1;.;
I re-created the problem by taking "." out of my classpath, so I'm pretty sure that's what your problem is.
Manavendra Chimakurthi
Greenhorn

Joined: Sep 04, 2003
Posts: 3
Thank you so much. That worked. But why did it work? Aren't the classes in the current directory available to other classes by default?
Manavendra Chimakurthi
Greenhorn

Joined: Sep 04, 2003
Posts: 3
Thanks Pradeep and Wayne. I got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Frustrating compilation "Cannot resolve symbol" error
 
Similar Threads
head first ejb pg:57 client problem!!!please help urgent
Problem with compiling the examples
problem with packages and classpath
JDate not found in JDateTest
Issue running ant.bat