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 Non static method error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Non static method error" Watch "Non static method error" New topic

Non static method error

shawn sandy

Joined: Jul 02, 2001
Posts: 12
could anyone explain why I get this error, and how to fix it? non-static method objectWrite(Golfer) cannot be referenced from a static context
here are the files...

Thanks in advance!
edited by Dave to put in code blocks
[ February 07, 2002: Message edited by: Dave Vick ]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Your method objectWrite is defined as an instance method but in main you are calling it as if it were a static method - you didn't give it a this:
calling it in main like this will work:
of course that is redundant to tell it the same object twice.
It looks like you just want a method that will save the given golfer to the file system. You can make the method static:
static public void objectWrite(Golfer player){} then it'll act the way you are using it or you could just make it an instance method of class Golfer and not have it take an arguement it would just work on the this object it gets in the method call. I'mmnot real proficient with serialization so I cant tell you the best implementation but I can show you whats wrong with you've got
hope that helps

I agree. Here's the link:
subject: Non static method error
It's not a secret anymore!