Reputation: 21
I surfed the net for 2 days, and I didn't find a solution formyproblem, so I decided to ask here. I'm doing a book exercise: "Write a program Client-Server with Java RMI, that return the sum of integer given by clients. It has to implement a method to add an integer, anda method to get the total". I'm facing with the Server-side.
The error the program returns is:
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
Here there are my classes: 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;
}
}
Remote Interface
public interface IContatore extends Remote{
int get() throws RemoteException;
void add(int i) throws RemoteException;
}
Remote Object
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);
}
}
Server
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();
}
}
}
Please, help me :S
Upvotes: 1
Views: 1603
Reputation: 11
In my experience, this has to do with the absolute path in the File System where the RMI Eclipse project is placed. I think you may have a blank, a space, in the path. So RMI is unable to parse the path and it is interrupted, ... then we get the 'malformed' exception. It might be near a 'c', and for this reason, you get the 'c' in the exception. I recommend you go to the file system, navigate to the project folder, and check the absolute path to the project. I bet you have a blank. Such as c:\Users\mylab c\MyProjects.... Did you notice the blank space?
Upvotes: -1