So, I got a 2D array (I initalised it at the beginning, because it was in use in two different methods - is there a better way of doing this?), but now when my method, initalise() runs, it's supposed to change the values of the array, but it doesn't, as my second method, toString(), and in my debugger both say that the 2D array variable seatArray is null, after the initalise() method finishes.
public class SeatLayout
{
int numberOfRows = 0;
int numberOfColumns = 0;
Seat[][] seatArray = new Seat[10][7];
private void initialise()
{
Seat[][] seatArray = new Seat[numberOfRows][numberOfColumns];
for(int i = 0; i < this.numberOfRows;++i)
{
for(int j = 0; j <this.numberOfColumns;++j)
{
if(i <=4)
{
if(j == 0 || j == this.numberOfColumns)
{
seatArray[i][j] = new Seat(SeatType.WINDOW, new Position(new Row(numberOfRows), new Column((char)(numberOfColumns+48))));
seatArray[i][j].setFirstClass(true);
}
public String toString()
{
for (int i = 0; i < this.numberOfRows;++i)
{
for (int j = 0; j < this.numberOfColumns;++j)
{
System.out.print(this.seatArray[i][j].toString());
I tried to include only the necessary code.