我不知道为什么,但这行代码给出了NullPointerException
. 我搜索了创建用户 obj 的数组。在Java中,再次但是,我找不到任何问题。
private State[] states;
.
.
.
private void initializeStates( )
{
states = new State[ stateNames.length ]; // Throws NullPointerException
for( int i = 0; i < stateNames.length; i++ )
{
states[i] = new State();
states[i].setName( stateNames[i] );
states[i].setColor( stateColors.getColor() );
}
} // End of initializeStates()
这是课程:
public class State
{
private String stateName;
private String color;
private boolean isStartState;
private boolean isFinalState;
State()
{
stateName = new String(); // Can this line cause nullPtrException?
color = new String(); // Can this line cause nullPtrException?
isStartState = false;
isFinalState = false;
}
public void setName( String name ){ stateName = name; }
public void setColor( String clr ) { color = clr; }
public void makeStart( ) { isStartState = true; }
public void makeFinal( ) { isFinalState = true; }
}