-2

I'm running this on an xml file and when I click on that particular button relating to this code it gives me an error. I think it has something to do with the arraylist combined with integers.

    public void doError(ActionEvent actionEvent) {
    ArrayList<Integer> integers =null;

    for (int i = 0; i < 100; i++) {
        integers.add(i);
    }
Coder
  • 1,917
  • 3
  • 17
  • 33

2 Answers2

2

ArrayList is never instantiated.

public void doError(ActionEvent actionEvent) {
ArrayList<Integer> integers = new ArrayList<Integer>();

for (int i = 0; i < 100; i++) {
    integers.add(i);
}
Luminous_Dev
  • 614
  • 6
  • 14
2

You need to initialize the ArrayList like this:

   ArrayList<Integer> integers = new ArrayList<Integer>();

Because you can't add integer to an ArrayList null

Abdelhak
  • 8,299
  • 4
  • 22
  • 36