• Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot find an interface error  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ..."
 
Rajendra Nath
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest Friedman-Hill. It's working now.
But i didn't understand the logic the way it has worked.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!