首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java.rmi.UnmarshalException: error unmarshalling

2011-11-26 
初学RMI 程序狂报异常!最近在看JAVA核心技术看到了RMI那里我照着书上打代码。基本上没怎么改动然后运行就狂

初学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


哪位朋友帮忙看下是怎么回事啊?   谢谢!!!!!!!!


[解决办法]
还有,这个问题最好是放到扩展类版块去问,这里是基础类版块!

热点排行