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

returning a value

Erkki Veps�l�inen
Greenhorn

Joined: Feb 10, 2004
Posts: 9
What is the reason that I get an error message "non-static method cannot be referenced from a static context" while trying to return a value from a class? what does it mean actually?
Thanks,
Erkki
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Non-static methods -- i.e., regular instance methods -- have to have an object of the class to operate on. Static methods don't need an object. Therefore, you can't call a non-static method from a static one without creating an object. Here's an example of code that will cause this error message:

And here's how you would fix the problem:


[Jess in Action][AskingGoodQuestions]
Erkki Veps�l�inen
Greenhorn

Joined: Feb 10, 2004
Posts: 9
Thanks for informing! Got it clear!
 
wood burning stoves
 
subject: returning a value