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 :(

[5384 byte] By [dnavrea] at [2007-11-27 5:02:57]
# 1
it says "java.io.NotSerializableException: org.ro2helpers.gateway.TestClassik"that means your class does not implement Serializable, so make it so
OnBringera at 2007-7-12 10:21:00 > top of Java-index,Core,Core APIs...
# 2
i can't do that(it should contain sockets and other not serializable objects) and i don't see any reason to do that because i'm using rmi as a service provider for jndi. objects that you publish in rmy registry should only implement Remote. :(
dnavrea at 2007-7-12 10:21:00 > top of Java-index,Core,Core APIs...
# 3
Remote remote = UnicastRemoteObject.exportObject(new TestClassik(), 0);ctx.bind("aaa", remote);
ejpa at 2007-7-12 10:21:00 > top of Java-index,Core,Core APIs...
# 4
Thx a lot :)already found a solution by extending TestClassic from UnicastRemoteObject :)
dnavrea at 2007-7-12 10:21:00 > top of Java-index,Core,Core APIs...