当我通过eclipse运行我的服务器代码时,我得到了以下异常:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: com.RMIInterface
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:413)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)我通过在cmd行中输入"start rmiregistry“启动了RMI注册表。打开一个标题为“c:\ProgramFiles\Java\jdk1.7.0\bin\rmiregistry.exe”的新窗口。在这条道路上,只有JDK。
我所有的.class文件都可以在这个路径上使用:d:\工作区\Study\bin\com。
在com文件夹下,我有三个文件"RMIInterface、RMIServer、RMIClient“。
当我从eclipse运行服务器代码时,我得到了上述异常。(即) RMIInterface未找到。但我把它放在同一个文件夹里。
我还应该做些什么来运行服务器呢?
这是我的服务器代码:
RMIServer serRef = new RMIServer();
try {
RMIInterface inref = (RMIInterface)UnicastRemoteObject.exportObject(serRef, 0);
Registry reg = LocateRegistry.getRegistry();
reg.bind("ServerObj", inref); -------->Exception in this line
} catch (AlreadyBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}发布于 2012-09-26 09:02:07
我认为问题在于您访问接口的方式。
就像你说的,Under the com folder I have all three files "RMIInterface, RMIServer,RMIClient".
如果所有文件都在同一个包/文件夹中,那么为什么要编写com.RMIInterface?
它应该是RMIInterface,因为您刚才提到的方式是在当前的com包中搜索另一个名为com的包。
我希望你明白我的意思。
编辑
在运行RMI程序时,我们确实需要运行rmiregistry。
您应该在rmiregistry启动服务器程序之前运行。
尝试从控制台或窗口中的CMD运行它。
在CMD中尝试rmiregistry或start rmiregistry。在从CMD运行时,我们确实需要从运行javac和java的相同文件夹/包启动rmiregistry。如果发生eclipse,我想您应该尝试从com文件夹运行rmiregistry。
更新
我认为,直到现在,您正试图从com文件夹中启动rmiregistry。试着从com文件夹中启动它。
尽管有D:\Workspace\Study\bin\com>start rmiregistry
试一试
D:\Workspace\Study\bin\start rmiregistry
发布于 2013-09-03 13:37:56
Remote Server Error:RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: mathInterface这个错误很容易解决,可以执行以下步骤:
(无论您的文件在哪里,启动rmiregistry)
参考资料:java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException)
https://stackoverflow.com/questions/12597723
复制相似问题