初学RMI 程序狂报异常!
最近在看JAVA核心技术 看到了RMI 那里 我照着书上打代码。 基本上没怎么改动 然后运行 就狂报异常!
代码如下:
yuancheng.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface yuancheng extends Remote {
String returnstring() throws RemoteException;
}
=======================================================
duixiang.java
import java.rmi.*;
import java.rmi.server.*;
public class duixiang extends UnicastRemoteObject implements yuancheng{
private String str=null;
public duixiang(String str) throws RemoteException
{
this.str=str;
}
public String returnstring() throws RemoteException
{
return this.str;
}
}
===================================================================
Server.java
import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;
public class Server {
public static void main(String[] args) {
try {
duixiang first=new duixiang("wufangdong");
duixiang second=new duixiang("wangdi");
Context namingContext=new InitialContext();
namingContext.bind("rmi:toaster",first);
namingContext.bind("rmi:microwave",second);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
贴出一些异常信息:
javax.naming.CommunicationException [Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: yuancheng]
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:122)
at com.sun.jndi.toolkit.url.GenericURLContext.bind(GenericURLContext.java:208)
at javax.naming.InitialContext.bind(InitialContext.java:359)
at duixiang.main(duixiang.java:27)
Caused by: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: yuancheng
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:385)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:343)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:116)
... 3 more
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: yuancheng
哪位朋友帮忙看下是怎么回事啊? 谢谢!!!!!!!!