aspose file tools*
The moose likes Beginning Java and the fly likes static and non-static errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static and non-static errors" Watch "static and non-static errors" New topic
Author

static and non-static errors

Paul Baker
Greenhorn

Joined: Feb 05, 2002
Posts: 6
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
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: static and non-static errors