File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static and non-static errors

 
Paul Baker
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic