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 Instantiating class in a static method 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 "Instantiating class in a static method" Watch "Instantiating class in a static method" New topic
Author

Instantiating class in a static method

akash gall
Greenhorn

Joined: Feb 07, 2013
Posts: 3
Hi everyone,

I am supporting this project. Now I am getting this error, Cannot make a static reference to the non-static method myMethod() from the type XMLParser2

From the static method, I am trying to call my method in another class (which is not static)

Is there any way this can be done, as I cant change the original method.

Thanks.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Welcome to the Ranch
That is a common mistake. You are trying to contact something from a static method, possibly the main method. You should consider whether you are right working in a static context in the first place. Then, you need to create an object reference and call methods on that.
 
Don't get me started about those stupid light bulbs.
 
subject: Instantiating class in a static method
 
Similar Threads
java.util.array not recognised
static method
Problem with Objects and Method Call
static
How main in superclass is called from subclass