This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "returning a value" Watch "returning a value" New topic

returning a value

Erkki Veps�l�inen

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?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

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

Joined: Feb 10, 2004
Posts: 9
Thanks for informing! Got it clear!
I agree. Here's the link:
subject: returning a value
Similar Threads
run time value assignment to a Final and public variable.
Initialization of static "constant" field with a non-static value
please explain the output
static final with object handle
Static variables usage