This site requires JavaScript, please enable it in your browser!
Greenfoot back
Peach
Peach wrote ...

2012/12/29

non-static methods

Peach Peach

2012/12/29

#
Hi, for some reason it keeps saying that non-static method setLocation(int,int) cannot be referenced from a static context when I try to compile my world. (the bold part in my code) What does that mean and how should i fix the problem? Here is my code: Lobster lobster2 = new Lobster(); addObject(lobster2, 50, 111); Lobster.setLocation(390,200); Lobster2.setLocation(28, 546);
danpost danpost

2012/12/29

#
The name of your lobster object is 'lobster2'. The class name that the object was created from is 'Lobster'. You cannot set the location of a 'class'; only an object. Try the following
Lobster lobster2 = new Lobster();
addObject(lobster2, 28, 546);
The line 'Lobster.setLocation(390,200);' tries to set the location of a class. The line'Lobster2.setLocation(28,546);' tries to set the location of an undefined object (Lobster2 is not lobster2 -- Java is case sensitive).
You need to login to post a reply.