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

2016/5/26

World not being constructed, no zero-argument constructor available?

moretinshop moretinshop

2016/5/26

#
So I have my game set up that there is a Controller class that inherits from World, and that is what will handle different classes communicating to each other. The controller class also uses setWorld() to set the current level. Greenfoot will not construct the world because it says it requires a zero-argument constructor, which I don't understand as the Controller constructor already has zero arguments. I am failing to see what I have done differently here to a different game in which I have done in the past which worked in an identical way. Controller:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import greenfoot.*;
 
public class Controller extends World
{
    private Level1 level1;
     
    public Controller()
    {   
        super(960, 540, 1);
         
        level1 = new Level1(this);
        Greenfoot.setWorld(level1);
    }
}
Level1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import greenfoot.*;
 
public class Level1 extends World
{
    private Player thePlayer;
    private Survivor survivor1;
    private Fog theFog;
    private Controller controller;
     
    public Level1(Controller c)
    {   
        super(960, 540, 1);
         
        controller = c;
danpost danpost

2016/5/26

#
Apparently, you are creating and setting active a Level1 world object before a Controller object is created. Right click on the Controller class in the classes section and select 'new Controller()' to have the Controller world the first initialized world.
moretinshop moretinshop

2016/5/26

#
My hero <3
You need to login to post a reply.