当前位置: 代码迷 >> J2SE >> java.rmi.UnmarshalException:   error   unmarshalling  
  详细解决方案

java.rmi.UnmarshalException:   error   unmarshalling  

热度:797   发布时间:2016-04-24 14:21:24.0
初学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)
  相关解决方案