Hi, I'm getting a "non-static method getId() cannot be referenced from a static context" error message. I'm trying to access a method from an extended class that cannot be made static because the information is constantly changing. I'm calling these methods from "public static void Main(String args)". Hope someone can help me!! paul
posted 13 years ago
If it is not static (ie: belongs to the whole class) then it must be called by a specific instance of the class. Therefore you need to create an instance of the class and use it to invoke the method.
Since the main method does not know which of the potential zillions of instances of this class that COULD be out there, and which you are refering to when you say getId(), you have to TELL it which specific object that you are talking about. However I get nervous when you say that something can not be static because it's value it constantly changing. So what?? There is nothing that says that the value of a static variable can not be constantly changing. Obviously I do not understand the scenario that you are coding to. Perhaps you could describe it a bit. [ March 10, 2002: Message edited by: Cindy Glass ]
"JavaRanch, where the deer and the Certified play" - David O'Meara