why java.io.NotSerializableException ?
hi
i have an application that should start an rmi registery and then put/get objects into it using JNDI.
When i'm running it i'm getting the following exception:]
javax.naming.CommunicationException [Root exception is java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: org.ro2helpers.gateway.TestClassik]
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:126)
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:131)
at javax.naming.InitialContext.bind(InitialContext.java:400)
at org.ro2helpers.gateway.ServerRegistery.startJNDIRegister(ServerRegistery.java:26)
at org.ro2helpers.gateway.ServerRegistery.<init>(ServerRegistery.java:33)
at org.ro2helpers.gateway.GatewayServer.<init>(GatewayServer.java:37)
at org.ro2helpers.gateway.GatewayServer.main(GatewayServer.java:69)
Caused by: java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: org.ro2helpers.gateway.TestClassik
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:120)
... 6 more
Caused by: java.io.NotSerializableException: org.ro2helpers.gateway.TestClassik
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
... 8 more
Sources:
ServerRegistery
package org.ro2helpers.gateway;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
publicclass ServerRegistery{
privatevoid startRMIRegistry()throws RemoteException{
LocateRegistry.createRegistry(1099);
}
privatevoid startJNDIRegister()throws NamingException{
Hashtable<String, String> env =new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.rmi.registry.RegistryContextFactory");
env.put(Context.PROVIDER_URL,"rmi://127.0.0.1");
Context ctx =new InitialContext(env);
ctx.bind("aaa", (Remote)new TestClassik());
}
public ServerRegistery(){
try{
startRMIRegistry();
startJNDIRegister();
}catch (RemoteException e){
// TODO Auto-generated catch block
e.printStackTrace();
}catch (NamingException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
TestClassik
package org.ro2helpers.gateway;
import java.rmi.RemoteException;
publicclass TestClassikimplements IServerRegistry{
publicint testFunction()throws RemoteException{
// TODO Auto-generated method stub
return 0;
}
}
IServerRegistry
package org.ro2helpers.gateway;
import java.rmi.Remote;
import java.rmi.RemoteException;
publicinterface IServerRegistryextends Remote{
publicint testFunction()throws RemoteException;
}
please help :(

