Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13077
| From | William Colls <william.colls@rogers.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Beginners Problem - Static reference to non-static method |
| Date | 2012-03-20 10:21 -0400 |
| Organization | National Capital Freenet, Ottawa, Ontario, Canada |
| Message-ID | <jka3p1$l8f$1@theodyn.ncf.ca> (permalink) |
| References | <jk9vfl$gfl$1@theodyn.ncf.ca> |
On 03/20/2012 09:07 AM, William Colls wrote:
> I am novice with Eclipse, and a beginner with Java, but I have 20+ years
> experience as a programmer - coming to OO late in life.
>
> I Have some code that looks like this:
>
> // begin java
>
> package com.mine.package
>
> class MyClass {
>
> import java.io.*
>
> public static void main() {
>
> try {
> runMyMethod(); // <---- error here
> }
> catch (Exception e) {
> System.out.println(e.getMessage());
> }
> }
>
> public void runMyMethod() throws Exception {
> // do some things
> }
> }
>
> // end java
>
> However, Eclipse generates the error "Cannot make static reference to to
> non-static method in type MyClass" at the point noted.
>
> I understand what it means (I think), but I don't understand why it is a
> problem, and more importantly - How to fix it. There is a whole bunch
> more stuff in the class. Making runMyMethod static fixes the problem
> here, but then everything else in the class also has to be static.
>
> Eventually, the class MyClass will be integrated into a much larger
> project, and the local main method goes away. I tried creating a
> seperate class with the main method, and importing MyClass. However,
> Eclipse seemed to be unable to resolve the runMyMethod from the imported
> class. But maybe I wasn't doing it properly.
>
> If anyone can offer guidance and/or suggestions as how best to proceed,
> I will be most greatful.
>
> Thanks all for your time.
>
> William.
>
>
Thanks to Patricia and Lew - so simple once you understand.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Beginners Problem - Static reference to non-static method William Colls <william.colls@rogers.com> - 2012-03-20 09:07 -0400 Re: Beginners Problem - Static reference to non-static method Patricia Shanahan <pats@acm.org> - 2012-03-20 06:13 -0700 Re: Beginners Problem - Static reference to non-static method Lew <noone@lewscanon.com> - 2012-03-20 06:34 -0700 Re: Beginners Problem - Static reference to non-static method William Colls <william.colls@rogers.com> - 2012-03-20 10:21 -0400 Re: Beginners Problem - Static reference to non-static method Gordon Levi <gordon@address.invalid> - 2012-03-21 02:15 +1100 Re: Beginners Problem - Static reference to non-static method Roedy Green <see_website@mindprod.com.invalid> - 2012-03-20 11:28 -0700
csiph-web