【问题标题】:the UnsupportedOperationException in RMIRMI 中的 UnsupportedOperationException
【发布时间】:2012-05-07 17:29:42
【问题描述】:

我做了一个简单的程序 但是当您在命令中运行客户端时 出现这个错误

 HelloClient exception:  java.lang.UnsupportedOperationException: Not supported yet.

这是我的编码

接口类

    import java.rmi.*;

    public interface HelloInterface extends Remote { 

     public String say() throws RemoteException;


   }

实现类

           import java.rmi.RemoteException;
           import java.rmi.server.UnicastRemoteObject;

         /** 
           *
           * @author x
           */
   public class HelloServerImpl extends UnicastRemoteObject implements HelloInterface {

   private String message; 

   public HelloServerImpl(String msg)throws RemoteException{
   message = msg;
   }


@Override
public String say() throws RemoteException {
    throw new UnsupportedOperationException("Not supported yet.");
}




 }

服务器类

     import java.rmi.Naming;

       /**
        *
        * @author x
        */
       public class HelloServer {
        public static void main (String []args ){
          try {
        Naming.rebind("HELLOSERVER", new HelloServerImpl("Hello word"));
        System.out.println("Hello Server is ready.");
    } catch (Exception ex) {
        System.out.println("Hello server failed: "+ ex);
    }


    }
    }

客户端类

          import java.rmi.Naming;

         /**
          *
          * @author x
          */
             public class HelloClient {
          public static void main(String[]args){

        HelloInterface hello;
        String url = "rmi://localhost/HELLOSERVER";


         try {
        hello = (HelloInterface)Naming.lookup(url);
        System.out.println(hello.say());
    } catch (Exception ex) {
       System.err.println("HelloClient exception:  " + ex);
    }

    }
   }

我准备写步骤但还是一样的错误

为什么??

【问题讨论】:

  • 而执行你写的代码的问题是什么?

标签: java rmi remoteexception


【解决方案1】:

这是你自己写的:

@Override
public String say() throws RemoteException {
    throw new UnsupportedOperationException("Not supported yet.");
}

当然会抛出异常。尝试实际返回一个字符串:

@Override
public String say() throws RemoteException {
    return "hello";
}

【讨论】:

猜你喜欢
  • 2019-12-20
  • 1970-01-01
  • 2021-03-07
  • 1970-01-01
  • 2020-04-13
  • 1970-01-01
  • 2015-12-27
  • 2011-08-10
相关资源
最近更新 更多