Я занимался серфингом в сети 2 дня, и не нашел решения проблемы, поэтому решил спросить здесь.Я делаю книжное упражнение: «Напишите программу Client-Server с Java RMI, которая возвращает сумму целого числа, данного клиентами. В нем должен быть реализован метод добавления целого числа и метод для получения суммы».Я сталкиваюсь с серверной стороной.
Ошибка, которую возвращает программа:
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.net.MalformedURLException: unknown protocol: c
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at java.rmi.Naming.bind(Unknown Source)
at ContatoreServer.main(ContatoreServer.java:15)
Caused by: java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at sun.rmi.server.LoaderHandler.pathToURLs(Unknown Source)
at sun.rmi.server.LoaderHandler.getDefaultCodebaseURLs(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 5 more
Вот мои классы: LocalObject
public class ContatoreLocale {
private int num;
public ContatoreLocale(){
this.num=0;
}
public synchronized int get(){
return this.num;
}
public synchronized void add(int i){
this.num+=i;
}
}
Удаленный интерфейс
public interface IContatore extends Remote{
int get() throws RemoteException;
void add(int i) throws RemoteException;
}
Удаленный объект
public class ContatoreRemoto extends ContatoreLocale implements IContatore{
Logger log= Logger.getLogger("global");
//Costruttore
public ContatoreRemoto() throws RemoteException{
super();
UnicastRemoteObject.exportObject(this, 0);
try {
Naming.rebind("Contatore", this);
//errore
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public int get(String nome) throws RemoteException{
return this.get();
}
public void add(String nome,int i) throws RemoteException{
this.add(i);
}
}
Сервер
public class ContatoreServer {
static Logger log= Logger.getLogger("global");
public static void main(String[] args) {
try {
ContatoreRemoto cr=new ContatoreRemoto();
log.info("Server Pronto");
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
Пожалуйста, помогите мне: S