java rmi error

  • Thread starter shaunak.adgaonkar
  • Start date
S

shaunak.adgaonkar

have already compiled server file it gets compiled but when i try to
compile my interface and client it gives me error that my server class
is not found or can not resolve the symbol... let me give u the
code .... any help is appreciated..

Server code is :

import java.rmi.*;

public interface SampleServer extends Remote
{
public int sum(int a,int b) throws RemoteException;
}



Client code is :

import java.rmi.*;
import java.rmi.server.*;

public class SampleClient
{
public static void main(String[] args)
{
// set the security manager for the client
System.setSecurityManager(new RMISecurityManager());
//get the remote object from the registry
try
{
System.out.println("Security Manager loaded");
String url = "//localhost/SAMPLE-SERVER";
SampleServer remoteObject =
(SampleServer)Naming.lookup(url);
System.out.println("Got remote object");
//narrow the object down to a specific one
//System.out.println("Location: " +
System.getProperty("LOCATION"));
// make the invocation

System.out.println(" 1 + 2 = " +
remoteObject.sum(1,2) );
}
catch (RemoteException exc)
{
System.out.println("Error in lookup: " + exc.toString());
}
catch (java.net.MalformedURLException exc)
{
System.out.println("Malformed URL: " + exc.toString());
}
catch (java.rmi.NotBoundException exc)
{
System.out.println("NotBound: " + exc.toString());
}


and interface code is :

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;

public class SampleServerImpl extends UnicastRemoteObject
implements SampleServer
{
SampleServerImpl() throws RemoteException
{
super();
}

public int sum(int a,int b) throws RemoteException
{
return a + b;
}

public static void main(String args[])
{
//set the security manager
try
{
System.setSecurityManager(new RMISecurityManager());

//create a local instance of the object
SampleServerImpl Server = new SampleServerImpl();

//put the local instance in the registry
Naming.rebind("SAMPLE-SERVER" , Server);

System.out.println("Server waiting.....");
}
catch (java.net.MalformedURLException me)
{
System.out.println("Malformed URL: " + me.toString());
}

catch (RemoteException re)
{
System.out.println("Remote exception: " + re.toString());
}

}
}


Now i use this
javac SampleServer.java .... it gets compiled
but when i use
javac SampleServerImpl.java it gives me error like this

SampleServerImpl.java : 6 Can not resolve symbol

Symbol : class SampleServer

Please help me out guys
 
J

John B. Matthews

I have little experience with rmi, but it looks somewhat like you're
following the Sun tutorial. I'll offer what help I can.

Watch your code wrap and tabs. If it's easy to read and compile, more
people are likely to look into the problem.

[...]
Server code is :

This looks more like a subinterface:

<http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.
1.3>
import java.rmi.*;

public interface SampleServer extends Remote
{
public int sum(int a, int b) throws RemoteException;
}

This compiles.
Client code is : [...]

Your Client code is missing some trailing braces; it doesn't compile.
and interface code is :

This looks more like a subclass that implements the subinterface you
defined above.
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;

public class SampleServerImpl extends UnicastRemoteObject
implements SampleServer [...]

javac SampleServerImpl.java gives me error like this

SampleServerImpl.java : 6 Can not resolve symbol

Symbol : class SampleServer

Your SampleServerImpl compiles correctly for me, which prompts me to ask
several questions:

Do your file names match your class names?
Does case matter on your operating system?
Are there hidden characters in your file(s)?
Is SampleServer.class in the current directory?
Is the current directory on your classpath?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top