Computer Science Canada Nonstatic/static Referencing |
Author: | Gryphon [ Sun Jun 01, 2008 3:08 am ] | ||
Post subject: | Nonstatic/static Referencing | ||
I am currently trying to make Monopoly in JCreator. I'm having a problem calling my methods and using my global variables in the main part of my program. The errors i'm getting all say: non-static method/variable (name) cannot be referenced from a static context. I have tried vigorously and without success to fix these problems, could someone please help me find a solution, any help would be greatly appreciated, thanks! My program is over 800 lines long so i'll provide just the main program and the first method i'm having trouble with.
By the way, I'm finding that if i try to make loadProps() static then the compiler still has a problem with the properties variable within the loadProps method, if i had to guess i'd say that the global variables are the problem. |
Author: | Reality Check [ Sun Jun 01, 2008 8:29 am ] |
Post subject: | Re: Nonstatic/static Referencing |
You are trying to reference a non-static variable within your static method. Putting a 'static' in front of your global varialbes should fix these problems. |
Author: | wtd [ Sun Jun 01, 2008 11:25 am ] |
Post subject: | RE:Nonstatic/static Referencing |
Static and non-static contexts are covered rather early in my Introduction to Java. Read it. ![]() |
Author: | Reality Check [ Sun Jun 01, 2008 3:04 pm ] |
Post subject: | Re: Nonstatic/static Referencing |
And yes I would definitely suggest going through wtd's intro to java. You will get a grasp of all the basics including static and non-static methods. |
Author: | Gryphon [ Sun Jun 01, 2008 3:36 pm ] |
Post subject: | Re: Nonstatic/static Referencing |
Thanks for the help, wtd your guide really helped me to understand what was wrong and reality your advice worked |
Author: | wtd [ Sun Jun 01, 2008 4:01 pm ] |
Post subject: | RE:Nonstatic/static Referencing |
Thanks. Glad you got something out of it. |
Author: | Reality Check [ Sun Jun 01, 2008 4:24 pm ] |
Post subject: | Re: Nonstatic/static Referencing |
No problem man, that's why we're here ![]() |