-1

For my highscore window I have 20 nodes inside a gridpane (20 labels). Now I want the gridpane to be as big as the window itself which is 450 x 450, and I was planning to do this by adding column & row constraints.

This is what I tried, but got a NullPointerException.

private ColumnConstraints[] columnConstraintses;
private RowConstraints[] rowConstraintses;

for (int i = 0 ; i < 10 ; i++) {
        columnConstraintses[i] = new ColumnConstraints(40);
        rowConstraintses[i] = new RowConstraints(40);
    }
m4t5k4
  • 55
  • 9

2 Answers2

1

if you define an array you have to initiate it and set a size.

private ColumnConstraints[] columnConstraintses = new ColumnConstraints[10];
private RowConstraints[] rowConstraintses = RowConstraints[10];
nano_nano
  • 12,351
  • 8
  • 55
  • 83
  • 1
    Thanks! I completely forgot that I had to write = new ... []; , and thought the array was already created with default size. – m4t5k4 Mar 09 '17 at 14:22
1

you did not initialize your arrays, try this:

private ColumnConstraints[] columnConstraintses = new ColumnConstraints[10];
private RowConstraints[] rowConstraintses = new RowConstraints[10];
Maarten Blokker
  • 604
  • 1
  • 5
  • 23