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

2014/1/20

Problems with my code

Necoo66 Necoo66

2014/1/20

#
I'm doing a project for a school assignment. I have to make an game which you can use to "learn math", but I've got a frustrating error. It gives me the Non static context error Would love to if anyone could help me out with this.
SommenWorld wereld = (SommenWorld) getWorld();
        Som computerUitkomst = new Som.getUitkomst();
        if(this.cijfer == computerUitkomst)
        {
            
        }
The getUitKomst() gives me the non static error
davmac davmac

2014/1/20

#
This:
Som computerUitkomst = new Som.getUitkomst();
Should probably be this:
Som computerUitkomst = new Som().getUitkomst();
Necoo66 Necoo66

2014/1/20

#
Ohh thanks... i guess i was getting mad.. But why should the class get the ()'s like for the functions ?
davmac davmac

2014/1/20

#
why should the class get the ()'s like for the functions ?
Because when you create a new instance of a class, you are actually calling its constructor.
Necoo66 Necoo66

2014/1/20

#
Ohh... that explains a lot. Got another question.. There is a greenfoot function Integer.parseInt(); Is there something like that but for Int to String ? I've been looking up but only that i can find is something about the adding a + "" to the variable. but in my case that doesnt do it.. I have to change it into a string so i can find the length of a int (and somehow the int.length doesnt work)
davmac davmac

2014/1/20

#
int i = 44;
String s = "" + i;
Works fine. Even:
int len = ("" + i).length();
You need to login to post a reply.