I do not know why but this line of code gives a NullPointerException. I searched creating array of an user obj. in Java, again but, I could not find any problem.
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()
And here is the class:
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; }
}