Java nullPointerException with getter and setters on an object
- by 12345
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));
}