Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

why java.io.NotSerializableException ?

843793May 21 2007 — edited May 21 2007
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;

public class ServerRegistery {

	private void startRMIRegistry() throws RemoteException {
		LocateRegistry.createRegistry(1099);
	}

	private void 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;

public class TestClassik implements IServerRegistry {

	public int testFunction() throws RemoteException {
		// TODO Auto-generated method stub
		return 0;
	}

}
IServerRegistry
package org.ro2helpers.gateway;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface IServerRegistry extends Remote {
	public int testFunction() throws RemoteException;
}
please help :(
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 18 2007
Added on May 21 2007
4 comments
1,446 views