Java nullPointerException with getter and setters on an object

Posted by 12345 on Stack Overflow See other posts from Stack Overflow or by 12345
Published on 2012-11-11T04:43:33Z Indexed on 2012/11/11 5:00 UTC
Read the original article Hit count: 117

Filed under:
|

I'm getting a nullPointerException below. Can someone explain why? Thanks!

private SpatialPooler spatialPooler;
private Region        region;
private Column        column33;


public void setUp()
{
    this.spatialPooler = new SpatialPooler();

    this.region = new Region(30, 40, 6, 8, 1.0f, 1, 1);

    this.column33 = this.region.getColumn(3, 3);
}

public void addActiveColumn(Column activeColumn)
{
    this.activeColumns.add(activeColumn); // nullPointerException here!
}

public Column getActiveColumn(int x, int y)
{
    for (Column activeColumn : this.activeColumns)
    {
        if (activeColumn.getX() == x && activeColumn.getY() == y)
        {
            return activeColumn;
        }
    }
    return null;
}

// in a test class that is in the same package.
public void testGetAndAddActiveColumn()
{
    this.spatialPooler.addActiveColumn(this.column33);
    assertNull(this.spatialPooler.getActiveColumn(3, 3));

    this.column33.setActiveState(true);
    assertEquals(this.column33, this.spatialPooler.getActiveColumn(3, 3));
}

© Stack Overflow or respective owner

Related posts about java

Related posts about nullpointerexception