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

2012/6/23

Null in Greenfoot

SPower SPower

2012/6/23

#
I pressed reset in a scenario I'm making, and I got this error: java.lang.NullPointerException at greenfoot.WorldVisitor.startSequence(WorldVisitor.java:73) at greenfoot.core.WorldHandler.startSequence(WorldHandler.java:873) at greenfoot.core.Simulation.runOneLoop(Simulation.java:491) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) I only got this once. I hope this helps for debugging.
SPower SPower

2012/6/23

#
I got an exception again!: java.lang.NullPointerException at greenfoot.ActorSet.getActorNode(ActorSet.java:127) at greenfoot.ActorSet.contains(ActorSet.java:92) at greenfoot.ActorSet.add(ActorSet.java:52) at greenfoot.TreeActorSet.add(TreeActorSet.java:172) at greenfoot.World.addObject(World.java:399) at HighscoresWorld.createUI(HighscoresWorld.java:27) at HighscoresWorld.<init>(HighscoresWorld.java:19) at MainMenu.buttonClicked(MainMenu.java:45) at Button.act(Button.java:111) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203)
erdelf erdelf

2012/6/23

#
to the second error, could I see HighscoresWorld`? to the first, copy the project.greenfoot file from an other project.
SPower SPower

2012/6/23

#
That is not the error: I only got the error once.
erdelf erdelf

2012/6/23

#
let me see.
SPower SPower

2012/6/23

#
Why? You can't fix it, can you? And I can't find a non instanciated object in all of my classes, and you can even tell from these lines: at greenfoot.ActorSet.getActorNode(ActorSet.java:127) at greenfoot.ActorSet.contains(ActorSet.java:92) at greenfoot.ActorSet.add(ActorSet.java:52) at greenfoot.TreeActorSet.add(TreeActorSet.java:172) that's is probably a greenfoot bug.
danpost danpost

2012/6/23

#
What is line 19 of your HighscoresWorld code?
SPower SPower

2012/6/23

#
createUI();
That is just a method with a bunch of this:
addObject(...);
kiarocks kiarocks

2012/6/23

#
If there's a bug, it's here:
int seq = ActorVisitor.getSequenceNumber(actor);
        int hash = seq % hashMap.length;
        ListNode hashHead = hashMap[hash];
        
        if (hashHead == null) {
            return null;
        }
        else if (hashHead.actor == actor) {
            return hashHead;
        }
        
        ListNode curNode = hashHead.nextHash;
        while (curNode != hashHead) {
            if (curNode.actor == actor) {//line 127
                return curNode;
            }
            curNode = curNode.nextHash;
        }

This is from the ActorSet class, line 114 to 131.
nccb nccb

2012/6/23

#
Hmm, I can't immediately see how you could get these errors (though it is clearly a bug in Greenfoot). Is there anything strange or advanced that you are doing in your scenario that you think might be related? I wonder if there is some bug to do with changing world and trying to have an actor in multiple worlds. Are you using multiple worlds in your scenario? If you're willing, you can upload the scenario to the site for us to have a look, or email it to us at support@greenfoot.org.
davmac davmac

2012/6/25

#
I can see how the first one might happen (and I've added a check to prevent it), the other one though should be pretty much impossible. SPower, are you messing with threads by any chance?
SPower SPower

2012/6/25

#
@davmac Yes, I think that's the error, sorry for that.
SPower SPower

2012/7/6

#
I'm so sorry greenfoot team: this time I got an exception, and I wasn't messing with threads: java.lang.NullPointerException at greenfoot.WorldVisitor.startSequence(WorldVisitor.java:73) at greenfoot.core.WorldHandler.startSequence(WorldHandler.java:873) at greenfoot.core.Simulation.runOneLoop(Simulation.java:491) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) I don't want to tease you: I just want to help
davmac davmac

2012/7/6

#
That's the same stack trace as you reported initially, and I've already found and fixed the bug that I think caused it (see my comment above).
SPower SPower

2012/7/7

#
O, sorry. I thought it was another :)
You need to login to post a reply.