This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes cannot find an interface error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "cannot find an interface error" Watch "cannot find an interface error" New topic
Author

cannot find an interface error

Rajendra Nath
Greenhorn

Joined: Nov 09, 2005
Posts: 27
hi all...

I'm implementing a small application which has an interface and an implementing class with the given package structure.

interface:

package math.src;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface MathFace extends Remote {
public int add(int a, int b) throws RemoteException;
}


implenting class

package math.src;

import math.src.MathFace;

import java.rmi.RemoteException;

public class MathImpl implements MathFace {
public int add(int a, int b) throws RemoteException {
return a + b;
}
}


these two classes are in web service dir.
when i try to compile, it's giving the following error:

C:\Web Service>javac -d bulid/classes math/src/MathImpl.java
math/src/MathImpl.java:3: cannot find symbol
symbol : class MathFace
location: package math.src
import math.src.MathFace;
^
math/src/MathImpl.java:7: cannot find symbol
symbol : class MathFace
location: package math.src
public class MathImpl implements math.src.MathFace {
^
2 errors


Regards
Rajendranath
Alik Elzin
Greenhorn

Joined: Sep 19, 2002
Posts: 15
Hi.
Try compiling MathFace.java first and then the implementing class.
Interfaces should be compiled as well - contrary to C/C++.

I also recommend using a Java IDE that can simplify the development process, such as IntelliJ, Eclipse, NetBeans...
There is a forum on Java IDEs and tools in Javaranch:
http://www.coderanch.com/forums/f-12/vc

Regards,
Alik.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24059
    
  13

Actually, most of us here at the Ranch recommend against beginners using an IDE; it's important to learn the basics first -- everyone benefits from a good understanding of the fundamentals.

The problem here is that javac is going to look for math.src.MathFace along the class path. It's going to try to find a directory named "math" in each directory mentioned as part of this configuration option. I'm betting you've got the CLASSPATH environment variable set, and it doesn't include an entry for "." (dot), the current directory. As a result, javac can't find it the interface.

The easiest and best way to fix this is to explicitly give the class path when you compile:

javac -classpath . -d build\classes math\src\MathImpl.java

That's "javac space dash classpath space dot space dash d ..."


[Jess in Action][AskingGoodQuestions]
Rajendra Nath
Greenhorn

Joined: Nov 09, 2005
Posts: 27
Thanks Ernest Friedman-Hill. It's working now.
But i didn't understand the logic the way it has worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot find an interface error
 
Similar Threads
How do I set the classpath for J2EE apis?
compilation error
NeedJ2EE 1.3 RI server Installation Help
Problem with MSDOS
question on my first EJB program? thanks all