我试图使用rmi注册表来获取远程对象的引用。这是我的代码
void initialize_server () {
//Look for other servers
String[] otherservers = null;
try {
otherservers = Naming.list("//localhost:1099/");
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
System.out.println("breakpoint");
if (otherservers != null) {
for (int i = 0; i < otherservers.length; i++) {
System.out.println(otherservers[i]);
IServer ref;
try {
ref = (IServer) Naming.lookup(otherservers[i]);
model.addServer(ref);
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (NotBoundException e) {
e.printStackTrace();
}
}
}
直到这里它工作正常但它当然没有找到任何服务器,因为没有。 所以,当我尝试在rmi上绑定一个像这样:
String server_rmi="rmi://localhost/" + servername;
try {
Naming.rebind(server_rmi,this);
} catch (RemoteException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
我收到一个永无止境的错误:
java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.UnsupportedClassVersionError: shared/IServer : Unsupported major.minor version 52.0
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:416)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:177)
at server.ServerController.initialize_server(ServerController.java:77)
at server.ServerController.<init>(ServerController.java:29)
at server.ServerStarter.main(ServerStarter.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
IServer界面是这样的:
package shared;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Vector;
public interface IServer extends Remote {
Vector<IClient> Search (String search) throws RemoteException;
void SaveReference (IClient x) throws RemoteException;
}
我使用ubuntu并且java -version命令返回此信息 java版&#34; 1.7.0_55&#34; Java(TM)SE运行时环境(版本1.7.0_55-b13) Java HotSpot(TM)64位服务器VM(内置24.55-b03,混合模式)
我已经失去了两个小时,而且我无法上班。 我真的不知道该怎么做,请帮助我。
答案 0 :(得分:2)
java.lang.UnsupportedClassVersionError:shared / IServer:Unsupported major.minor版本52.0
这让我觉得您已经尝试使用比用于编译它的JDK更低版本的JRE来运行您的应用程序。让他们甚至摆脱这个错误