• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

urgent help

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 = "127.0.0.1";
String lookupName = "xyz";
String hostName = "rmi://" +host+ "/" +lookupName;
public static void main (String [] args){
String m = "";
try{
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();
obj.Validate();
}
==========
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,
sachin
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic