我在下面看到nullPointerException。有人能解釋爲什麼嗎?謝謝!對象上有getter和setter的Java nullPointerException
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));
}
如何你打電話給你的'testGetAndAddActiveColumn'? –
我在這裏寫了註釋// nullPointException! –
通過查看代碼,似乎'activeColumns'是一個列表。您需要初始化'activeColumns'的列表。 –