-1

I'm trying to use the rmi registry to get a reference of a remote object. This is my code

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();
            }

        }
    }

And until here it works fine but it doesn't find any server of course, cos there is none. So when i try to bind one at the rmi like this:

    String server_rmi="rmi://localhost/" + servername;
    try {
        Naming.rebind(server_rmi,this);
    } catch (RemoteException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

I get an error that never ends:

 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)

The IServer interface is this:

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;
}

I'm using ubuntu and the java -version command returns this java version "1.7.0_55" Java(TM) SE Runtime Environment (build 1.7.0_55-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

I've lost two hours on this one and I cant get it to work. I really don't know what to do, please help me.

The error

user207421
  • 305,947
  • 44
  • 307
  • 483
Jack
  • 171
  • 2
  • 16
  • 1
    You must have compiled your `IServer` using a different version of JRE and you are using a different compiled version of `IServer` – Sajan Chandran May 25 '14 at 17:08
  • If you are using Eclipse: Delete and Add the same JRE to your project and then restart Eclipse. I do suspect a bug on Eclipse because this solved the problem for me several times... – abronan May 25 '14 at 17:14
  • I have recompiled the entire project, everything works if i comment those line. If they get executed there's the error. – Jack May 25 '14 at 18:13

1 Answers1

3

java.lang.UnsupportedClassVersionError: shared/IServer : Unsupported major.minor version 52.0

This makes me think that you have tried to run your application with a lower version of JRE than the JDK you used to compile it. Make them even to get rid of this error

Jorge_B
  • 9,712
  • 2
  • 17
  • 22
  • 1
    Yeah that was the first thing i read online about that error. the point is that it seems to me that i'm using jdk and jre 1.7. When i type java -version or javac - version it says 1.7, and in the ide i'm using jdk 1.7 as fodler for the jdk – Jack May 25 '14 at 18:02
  • 1
    Make sure your IDE is compiling with that version, it looks like that it is compiling with JDK 8 – Jorge_B May 25 '14 at 18:43
  • 2
    Compare the output of 'Java -version' ands 'javac -version'. You will find that they're different. – user207421 May 25 '14 at 22:43