[Edit - added code tags - see UseCodeTags for details]
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static variable this cannot be referenced from a static context
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
this was the error i got, could you please help me find out the problem?
Also, I doubt that the code you posted is all the code you tried to run.
rahul aditya wrote:sorry, but i use net beans.. is there any compile option in net beans?
As I recall, Netbeans (like Eclipse) compiles on the fly, so you probably have a few red markers in your text.
rahul aditya wrote:yes, i couldn't find out what the error is? so i posted it here..
Well usually, if you click (or hover) on the offending line, it'll tell you precisely what the error is (and maybe suggest ways to correct the problem).
If you still have problems, post the message you don't understand here (the whole message; exactly as it was given to you).
rahul aditya wrote:it says non-static content this cannot be referenced from static content
And you still can't see what the problem is?
Look at your class definitions. What you have defined are inner classes, which is almost certainly NOT what you want (I can still count the number of inner classes I've defined on my fingers after 11 years of Java).
An instance of an inner class needs a reference to an instance of its enclosing class. You need an instance of GameShape to create the instances of PlayerPiece and TilePiece on in lines 27 and 28. Since the main method is static, you don't have an implicit instance of GameShape to create those instances on.
In this example, there is no reason why the classes PlayerPiece and TilePiece should be inner classes. Move them out into their own source files, as top-level classes.
Another way to solve this is to make PlayerPiece and TilePiece nested classes instead of inner classes. A third way would be to change your main method to create an instance of GameShape first, and then to create the PlayerPiece and TilePiece instances on the instance of GameShape. But since there isn't a good reason to make PlayerPiece and TilePiece inner classes, I think making them top-level classes would be the best solution here.