Re: Input/Output program Compiles but doesn't run
- From: "Carl" <c.groner@xxxxxxxxx>
- Date: 30 Mar 2006 11:24:05 -0800
janicethorne via JavaKB.com wrote:
Thanks for your reply. Yes, I found that out when I added the static modifier
to the code and tried to compile it. I then declared my variables private and
static along with making the main method static. The only error I am getting
now is:
C:\Documents and Settings\JThorne\Desktop\Homework\Program81.java:74: non-
static variable this cannot be referenced from a static context
button = new ButtonHandler();
The button is in my main method. Why is this error occurring?
Just as the message states, you are attempting to access the non static
variable name "this" from within a static context.
I think you need to re-think your solution to your original problem.
Although it may satisfy the compilers requirements, it is unecessary
overuse of the static modifier.
The problem with your first code was not that your method was not
static, but that you were missing a main method.
I would suggest going back to your original source, renaming the method
you had named main() to something more descriptive of what it does
(like showWindow() ?) and creating a correct main() method that
instantiates the object and calls this new method. There is no good
reason to have to declare all of your GUI components static.
Hope this helps,
Carl.
.
- References:
- Input/Output program Compiles but doesn't run
- From: janicethorne via JavaKB.com
- Re: Input/Output program Compiles but doesn't run
- From: Carl
- Re: Input/Output program Compiles but doesn't run
- From: janicethorne via JavaKB.com
- Input/Output program Compiles but doesn't run
- Prev by Date: Re: Javadoc search tool ... is this new ???
- Next by Date: [OT] Re: File IO -- Reading Config Files Easily
- Previous by thread: Re: Input/Output program Compiles but doesn't run
- Next by thread: A question about a generic method
- Index(es):