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

2018/6/4

Help! The world constructor threw an exception.

dave6969 dave6969

2018/6/4

#
Worked before. Suddently after re-opening simulation it stopped working.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
public class ball extends Actor
{
    private double posx,posy,vx,vy,ax,ay,dt=0.1;
    private int Powerx;
    private int Powery;
    public void addedToWorld(World myworld)
    {
       String input = Greenfoot.ask("What do you want the power horizontal to be? Note only integers");
       String input2 = Greenfoot.ask("What do you want the power vertical to be? Note only integers");
       Powerx = Integer.parseInt(input);
       Powery = Integer.parseInt(input2);
       posx=getX();
       posy=getY();
       ax=0;
       ay=10;
       vx=20;
       vy=-20;
        
    }
    public void act()
    {
         
        posx+=vx*dt+-(Powerx)*ax*dt*dt;
        posy+=vy*dt+-(Powery)*ay*dt*dt;
         
        vx+=ax*dt;
        vy+=ay*dt;
        setLocation((int)posx,(int)posy);
          
    }   
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
 
public class myworld extends World
{
 
    public myworld()
    {   
       super(600, 400, 1,false);
       addObject(new ball(),100,getHeight()-100);
        
    }
}
and the message i get in terminal java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:542) at java.lang.Integer.parseInt(Integer.java:615) at ball.addedToWorld(ball.java:12) at greenfoot.World.addObject(World.java:428) at myworld.<init>(myworld.java:10) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at greenfoot.core.Simulation.newInstance(Simulation.java:617) at greenfoot.platforms.ide.WorldHandlerDelegateIDE.lambda$instantiateNewWorld$7(WorldHandlerDelegateIDE.java:430) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:502) at greenfoot.core.Simulation.maybePause(Simulation.java:305) at greenfoot.core.Simulation.runContent(Simulation.java:218) at greenfoot.core.Simulation.run(Simulation.java:211)
dave6969 dave6969

2018/6/4

#
Pls help
danpost danpost

2018/6/4

#
dave6969 wrote...
Pls help
Try this for you myWorld class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import greenfoot.*;
 
public class myworld extends World
{
    public myworld()
    {
       super(600, 400, 1,false);
    }
     
    public void started()
    {
        if (!getObjects(ball.class).isEmpty()) return;
        addObject(new ball(),100,getHeight()-100);
    }
}
I do not think the ask works during initial world construction.
dave6969 dave6969

2018/6/4

#
Thanks!
You need to login to post a reply.