File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Murach's Java Servlets and JSP this week in the Servlets 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!
Consider Paul's rocket mass heater.
subject: returning a value
Similar Threads
please explain the output
static final with object handle
Static variables usage
Initialization of static "constant" field with a non-static value
run time value assignment to a Final and public variable.