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

2020/6/9

Using blockLists help

jay4221 jay4221

2020/6/9

#
I generate a blocklist within the constructor of my world and then call it from my actor after but I keep on getting Null Pointer Exceptions on that line and I'm not too sure what's up. this is the code in my world class to make the blocklist
//Create block objects and assign them to a list
        blockList = new ArrayList();
        for (int i = 0; i < numNewBlocks; i++) {
            blockList.add(newBlock(sizeBlock,getWidth(),Greenfoot.getRandomNumber(maxOfRange),maxOfRange,debug)); 
            addObject( (Actor)blockList.get( blockList.size()-1 ),  getWidth()/2, (i*sizeBlock)+(sizeBlock/2) );
        }
here I have an act method within my world which I call my actor from.
public void act() {
        //Step by Step Bubble Sort
        CocktailShakerVisualizerOkabe sort = new CocktailShakerVisualizerOkabe();
        //addObject(sort,10,10);
        sort.move();
    }
this is where i call the list from my actor class and is where my error is occurring.
{
        if (size <= 0){
            blockList = ((SortingVisualization)getWorld()).getBlockList(); // getting null value???
            size = blockList.size();
            System.out.println(blockList.size());
        } 
        
danpost danpost

2020/6/9

#
Where is newBlock defined? (or should it be new Block on line 4 in the first code set)?
jay4221 jay4221

2020/6/12

#
It should be new Block but the formatting got rid of the space when I posted it here. It has the proper space in my code.
danpost danpost

2020/6/12

#
jay4221 wrote...
It should be new Block but the formatting got rid of the space when I posted it here. It has the proper space in my code.
Where is the above if statement placed in your code?
jay4221 jay4221

2020/6/13

#
it is the first line of my move() method within the actor class.
danpost danpost

2020/6/13

#
jay4221 wrote...
it is the first line of my move() method within the actor class.
Show act method and move method of the class.
You need to login to post a reply.