I am getting: java:830: non-static method createDocument(java.io.InputS tream,boolean,boolean) cannot be referenced from a static context error when i try to compile the code. Can any one tell me why it sbeing caused and how do i go about correcting it. The error is occuring near EOXMLUtils.createDocument
It appears that you need to either create an instance of EOXMLUtils and call the method using that instance, or declare the method static within EOXMLUtils. (The second option seems more likely for a "utility" class.)
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
This is a general problem. Whenever you declare a method static, it applies without change to the class, the whole class and nothing but the class. So, whichever object you are coming from, it is exactly the same. So you can call a static method from an object ("non-static"), but not vice versa.
If you call an instance method or instance variable ("non-static") from a static method, the static method cannot tell how many objects there might or might not be. So, the compiler will complain. Otherwise, if there are several objects of the class, the static method might call the non-static method on the wrong object.
Usually whenever I have had that compiler error, I have been trying to access an instance member of the same class from its static methods. So is your method a member of EOXMUtils? I agree with Marc Weber that you can create an instance of the class from within a static method (after all, that is what you do if you have a main method within the same class which does something), or set the method you are calling static.
Joined: Sep 19, 2005
Thanks guys !
It really helped me out. Well i created a instance for EOXMLUtils.
subject: non-static methos cannot be referenced from static context?