I have a 3x3 array of MSTextField which is a class I created which extends JTextField . I'm trying to set all of the text fields to display the empty string ( "" ). My problem is I'm getting a nullPointerException at the end of the method which is supposed to do this. I think the problem might be that I haven't initialized the array yet (earlier I thought that I was doing this by setting each text field to "" but I think I was wrong). How do I initialize an array of MSTextField so that I can set the text? Also, once they're initialized will textFieldArray[row][column].setText( "" ); at the end of my for loops work?

5 Years
Discussion Span
Last Post by SMITA6076

When using arrays of objects, there are two steps.
One: create the array object. (Yes arrays are very like objects)
Two: fill the array with the objects

You probably have not done step two.

textFieldArray[j] = new TextField(); // set i,j element to a TextField


Thank you! I don't know why I couldn't figure that out myself. I tend to over-think things expecting them to be harder than they really are. Thanks Again!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.