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

2020/8/18

my string name isn't working

ninjapuffin ninjapuffin

2020/8/18

#
something happened and I don't know why but I'm not being able to make a name for my string can you guys help me
ninjapuffin ninjapuffin

2020/8/18

#
this is my code
public class Piano extends World
{
    String name;
    name = "Fred";
    /**
     * Make the piano.
     */
    public Piano() 
    {
        super(800, 340, 1);
        addObject (new Key("g", "3a.wav"),300, 140);
        int i = 0;
        while(i < 100)
        {
            addObject(new Key("g", "3a.wav"),i*63 + 54 , 140);
            i = i + 1;
        }
    }
}
hope you find the mistake
ninjapuffin ninjapuffin

2020/8/18

#
this needs fixing
 String name;
    name = "Fred";
danpost danpost

2020/8/18

#
ninjapuffin wrote...
something happened and I don't know why but I'm not being able to make a name for my string << Code Omitted >>
Line 4, by itself, is an executable statement and cannot be placed in the class outside of method or constructor brackets ( "{" & "}" ). Either move the line to somewhere between line 10 and line 13 or between lines 17 & 18 OR combine it with line 3 as:
String name = "Fred";
ninjapuffin ninjapuffin

2020/8/19

#
thanks it worked
You need to login to post a reply.