Results 1 to 4 of 4
- 09-24-2012, 05:37 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 29
- Rep Power
- 0
non static method cannot be referenced from a static context
Could someone please tell me why i'm getting this error ?
non static VARIABLE cannot be referenced from a static context
Thank you !
Java Code:public class House{ private String string1; public House(){} public String Method1{ // do stuff return string1 } public int Method2(String x){ // do stuff } public static void main (String args[]){ Method1(); Method2(string1); } }Last edited by Dex; 09-24-2012 at 06:37 PM.
- 09-24-2012, 06:26 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: non static method cannot be referenced from a static context
Suppose I want to say hello to you; in java that translates to me.sayHelloTo(you) where me and you are two objects of class Human. But that also implies that there has to be a 'me' and a 'you' and that is exactly your error: you want a House object to Method1 or Method2 but there is no House object (b.t.w. by convention method names start with a lower case letter).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-24-2012, 06:37 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 29
- Rep Power
- 0
- 09-24-2012, 06:47 PM #4
Member
- Join Date
- Mar 2012
- Posts
- 29
- Rep Power
- 0
Similar Threads
-
Non static method printBoard(boolean) cannot be referenced from a static context
By warp in forum New To JavaReplies: 3Last Post: 05-31-2012, 07:56 PM -
Error in Code: Non-static method cannot be referenced from a static context
By oaklandsbest in forum New To JavaReplies: 9Last Post: 06-10-2011, 12:40 AM -
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 method cannot be referenced from a static context.
By blackstormattack in forum New To JavaReplies: 5Last Post: 05-07-2009, 04:05 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


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks