Results 1 to 6 of 6
- 03-20-2009, 01:28 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
non-static method add(double,double) cannot be referenced from a static context
while working the RMI program, i saw the erroe message " non-static method add(double,double) cannot be referenced from a static context".
the program is:
interfare pgm:
import java.rmi.*;
public interface intf extends Remote
{
double add(double d1,double d2) throws RemoteException;
}
implementation pgm:
import java.rmi.*;
import java.rmi.server.*;
public class impl extends UnicastRemoteObject implements intf
{
public impl() throws RemoteException
{}
public double add(double d1,double d2)throws RemoteException
{
return d1+d2;
}
}
server pgm:
import java.rmi.*;
import java.net.*;
public class serv
{
public static void main(String args[])
{
try
{
impl implref=new impl();
Naming.rebind("serv",implref);
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
}
}
client pgm:
import java.rmi.*;
public class clie
{
public static void main(String args[])
{
try
{
String surl="rmi://"+args[0]+"/serv";
intf intfref=(intf)Naming.lookup(surl);
System.out.println("the first number is:"+args[1]);
double d1=Double.valueOf(args[1]).doubleValue();
System.out.println("the second number is:"+args[2]);
double d2=Double.valueOf(args[2]).doubleValue();
System.out.println("the sum is:" + intf.add(d1,d2));
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
}
}
plz tell the correction as soon as possible.
i am waiting for the result.............
- 03-20-2009, 02:19 PM #2
A static method can only invoke instance methods through an instance of the class. Either make the instance method static, or instantiate the class and use the instance to access the method.
- 03-20-2009, 05:19 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
This is one of the fine tutorial found on the web in the past, about static members. If you can just look at it.
The Essence of OOP using Java: Static Members
And also, you've post your question on wrong place. Please don't do it again. Choose the correct sub-forum before posting again. So in that way you can find much better solutions for your question. Good luck!
- 03-21-2009, 10:58 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
thanks...........
- 03-21-2009, 02:46 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Welcome. If you have solve the problem please mark the thread solved. It really helpful to all other members as well, who's looking into your thread.
- 03-21-2009, 09:32 PM #6
Senior Member
- Join Date
- Mar 2009
- Location
- USA
- Posts
- 127
- Rep Power
- 0
Similar Threads
-
non-static member can not be referenced from a static context
By christina in forum New To JavaReplies: 3Last Post: 03-20-2009, 12:35 AM -
Method cannot be referenced from a static context - HELP
By jmorris in forum New To JavaReplies: 11Last Post: 11-19-2008, 03:13 AM -
Non-Static method in static context error
By wizmang in forum New To JavaReplies: 4Last Post: 04-24-2008, 08:51 AM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks