Results 1 to 6 of 6
- 10-15-2010, 03:58 AM #1
Member
- Join Date
- May 2010
- Posts
- 34
- Rep Power
- 0
non-static variable cannot be referenced from a static context
I tried googling, but still can't figure this out:
I've got a GUI class and another class.
I want to say when a radio button is selected in the gui class, it changes a variable.
-variable--1 of the button method bodys-Java Code:private int variable = 0;
-getMethod-Java Code:~~button header~~ variable = 2;
Java Code:public int getVariable() { return variable; }
And in the other class:
The Error appears on the line int i = classGUI.getVariable();Java Code:public int getVariableHere(){ int i = classGUI.getVariable(); return i; }
-
Are you calling the getVariable method on the class or on an object of the class? You probably should be doing the latter.
- 10-15-2010, 04:08 AM #3
Member
- Join Date
- May 2010
- Posts
- 34
- Rep Power
- 0
getVariable() is getting this: private int variable = 0;
-
- 10-15-2010, 04:16 AM #5
Member
- Join Date
- May 2010
- Posts
- 34
- Rep Power
- 0
THANK YOU! It has compiled now.
-
Similar Threads
-
Non-static method cannot be referenced from a static context
By GRoss in forum New To JavaReplies: 7Last Post: 05-19-2010, 11:12 AM -
non-static variable grade cannot be referenced from a static context
By pictianpravin in forum New To JavaReplies: 3Last Post: 02-11-2010, 09:59 AM -
non-static member can not be referenced from a static context
By christina in forum New To JavaReplies: 3Last Post: 03-20-2009, 12:35 AM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks