aspose file tools*
The moose likes Beginning Java and the fly likes Compiler error: Symbol not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiler error: Symbol not found" Watch "Compiler error: Symbol not found" New topic
Author

Compiler error: Symbol not found

Lenord Daly
Greenhorn

Joined: Oct 03, 2009
Posts: 4

I am back to java coding after 9 years and am having trouble getting started.
I am using jdk 1.6.


This is ITest.java
-------------------------------
package com.ibm.jaxws.tutorial.service ;

public Interface ITest {
public int getNumber() ;
}

This is Test.java
--------------------
package com.ibm.jaxws.tutorial.service ;

public class implements Test {
public int getNumber () { return (5*5) ; }
}

Now compile the interface. Current working dir is C:\jax-ws\com\ibm\jaxws\tutorial\service
> c:\sun\sdk\jdk\bin\javac -cp . ITest.java

Works great and I see the ITest.class file in the current working directory as expected.

Now I compile the implementing class --->> This class fails to compile
> c:\sun\sdk\jdk\bin\javac -cp . Test.java

Test.java:5 cannot find symbol
symbol: class ITest
public class Test implements ITest {

The above 3 lines are output of the compiler.

What am I doing wrong? Why can't the compiler resolve/find ITest.class and compile Test.java?


Thanks.

Len
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Lenord Daly wrote:What am I doing wrong? Why can't the compiler resolve/find ITest.class and compile Test.java?

Your compiled ITest class belongs to the com.ibm.. package. It's in the current directory right? Since you are setting the classpath to current directory compiler looks for a package hierarchy as in the package declaration within the current directory. For that to work you should add "-d ." switch to the "javac" when compiling the interface, then the class should compile successfully.



SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Until you are back in practice, I suggest you try leaving out the package names from all your code.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Lenord Daly
Greenhorn

Joined: Oct 03, 2009
Posts: 4

That was it!! Thank you Vijitha.

My current working dir was c:\jax-ws\com\ibm\jaxws\tutorial\service

> javac -cp . Test.java {was looking for the class path starting with the current directory and could not find the ITest.class file}

Changed current working dir to c:\jax-ws

> javac -cp . com\ibm\jaws\tutorial\service\Test.java

Now compiles and I am unblocked.

Also like the idea of staying away from packages for the next few days. Best to reduce the degrees of freedom when it
comes to training.

Thanks again to the two of you for your help.

Len
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Compiler error: Symbol not found