java - "non-static method makeHands() cannot be referenced from a static context" What does this mean, and how do I avoid it? -


when try run program, above quoted error. making makehands static ends in disaster, , making main non-static nothing. do?

http://pastebin.com/xpdkk7xr

to save space, code @ link.

write main method this:

public static void main(string[] args) {     new main().new deck().makehands(); } 

the explanation little convoluted try make clearer.

basically deck inner class of main class. 1 feature of inner classes (if aren't static in case) fact instances can't exist without instance of outer class. each instance of deck needs have reference instance of main class , can't create deck instance if don't have main instance available.

the syntax pasted above make sure proper instances exist: first create main instance , after create deck instance pointing main instance created before. call non static method makehands().

the more comprehensive explanation available here: http://download.oracle.com/javase/tutorial/java/javaoo/nested.html


Comments