0
我想從教程(http://java.sun.com/developer/onlineTraining/rmi/RMI.html)上運行jguru的示例RMI,但它們沒有在命令行中編譯,所以我無法運行rmic並前進教程:jGuru RMI示例不編譯
$javac Calculator.java
$javac CalculatorImpl.java
CalculatorImpl.java:6: cannot find symbol
symbol: class Calculator
implements Calculator {
^
1 error
兩個類都完全一樣,他們是在jguru教程: 接口:
public interface Calculator
extends java.rmi.Remote {
public long add(long a, long b)
throws java.rmi.RemoteException;
public long sub(long a, long b)
throws java.rmi.RemoteException;
public long mul(long a, long b)
throws java.rmi.RemoteException;
public long div(long a, long b)
throws java.rmi.RemoteException;
}
類:
public class CalculatorImpl
extends
java.rmi.server.UnicastRemoteObject
implements Calculator {
// Implementations must have an
//explicit constructor
// in order to declare the
//RemoteException exception
public CalculatorImpl()
throws java.rmi.RemoteException {
super();
}
public long add(long a, long b)
throws java.rmi.RemoteException {
return a + b;
}
public long sub(long a, long b)
throws java.rmi.RemoteException {
return a - b;
}
public long mul(long a, long b)
throws java.rmi.RemoteException {
return a * b;
}
public long div(long a, long b)
throws java.rmi.RemoteException {
return a/b;
}
}
環境瓦爾: (@Windows XP)
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20
CLASSPATH=C:\Program Files\Java\jdk1.6.0_20
Path=C:\Program Files\Java\jdk1.6.0_20\;...
好,我認爲這是沒有必要的,因爲他們是在同一目錄(屬於到相同的包<默認包>) – AndreDurao 2010-09-09 18:03:50
所以我導入了「導入計算器;」並給我2個錯誤:CalculatorImpl.java:1:'。'預計 進口計算器; ^ CalculatorImpl.java:1:';'預計 進口計算器; ^ 2錯誤 – AndreDurao 2010-09-09 18:04:22
嗯,我以爲你刪除了'package'語句。你的代碼在我的電腦上運行良好,沒有'package'(和'import')。但是這兩個java文件需要放在同一個文件夾中。 – 2010-09-09 18:16:13