[英]the UnsupportedOperationException in RMI
I worked a simple program But when you run the client at the command This error appears 我工作了一个简单的程序但是当您在命令运行客户端时出现此错误
HelloClient exception: java.lang.UnsupportedOperationException: Not supported yet.
this my coded 这是我的编码
Interface class 接口类
import java.rmi.*;
public interface HelloInterface extends Remote {
public String say() throws RemoteException;
}
implement class 实施课程
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.");
}
}
Server class 服务器类
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);
}
}
}
Client class 客户类
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);
}
}
}
I am prepared to write the steps but still the same error 我准备编写步骤,但仍然是同样的错误
why?? 为什么??
Well you wrote this yourself: 那你自己写了这个:
@Override
public String say() throws RemoteException {
throw new UnsupportedOperationException("Not supported yet.");
}
Of course it throws an exception. 当然它会引发异常。 Try to actually return a string:
尝试实际返回一个字符串:
@Override
public String say() throws RemoteException {
return "hello";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.