Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

urgent help  RSS feed

sachin dabhade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
i need to submit my assignment and got a problem with my code in RMI.
can anybody take me out of the sea???
i have a simple application as follows.
client side is swing where i have a window asking for user name and password.
there is interface called inter.
i declared method validate in interface.
and there is a server.
server has a method validate.
validate is suppose to check user id and password.
the server and interface are compiled finely with no problem.
but i am getting error in client.
below is extract of my code
Hello obj;//Hello is interface
String host = "";
String lookupName = "xyz";
String hostName = "rmi://" +host+ "/" +lookupName;
public static void main (String [] args){
String m = "";
Error here >>>>>>>obj = (Hello)Naming.lookup(hostName);
catch(Exception ex){}

public void actionPerformed (ActionEvent ae){
if (ae.getActionCommand().equals("Login")){
String uid = jtf.getText();
String pwd = jpf.getText();
i am getting 2 errors as "Non static variable i.hostName and ii.obj cannot be referenced from a static contest.
can anybody tell me anything about the error and how to get rid of it?
also i want to know how to send parameters to the method defined in server from the client in RMI.
thank you,
James Cook
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having just submitted my project successfuly today, I think I can answer these.
your object and hostname are being accessed from your static main() method. This is not allowed: static methods can ONLY access class variables (i.e. fellow statics), becuase there is no this.
When you pass parameters, for them to be recognized by RMI at all, they must fall into one of the following 2 categories:-
a) they must be remote objects, or if not,
b) they must be serializable (i.e. implement the Serializable Marker Interface).
Any parameters passed or retrieved which don't satisfy either of these criteria will fail.
The remote objects get passed by "reference" i.e. the receiver receives a stub which communicates with the actual object on the other side of the wire, whereas the serializable ones get passed by "value" i.e. they're serialized at the sending end and deserialized at the receiving end which is thus a copy.
Hope these comments help.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!