-4

I am creating a program to store different types of lawnmowers in an ArrayList. There are 4 types of mowers that all inherit from Mower. I am new to oop. Why do I get this error when I try to add a mower to my ArrayList?

Method to read mower data from a file path

Mower class

Method to add Mower to arrayList

Main class

Output with error

I tried different syntax for initializing LawnTractor but i kept getting the same result.

  • 1
    The error message tells you the issue is in `MowerWareHouse` class but you didn't provide that. Also, you should post the actual code here, not screenshots which cannot be run/copied/pasted/etc.. – takendarkk Mar 30 '23 at 17:07
  • 2
    Do not post pictures of code. nobody can run that. Edit the question and post as text as a [mcve]. Take the [tour] and read [ask] – OldProgrammer Mar 30 '23 at 17:07

1 Answers1

0

For future reference, it's a lot easier for people to help if you copy/paste your code instead of sending screenshots.

Anyways, it looks like your mowers object in MowerWareHouse is null; I'm assuming you never instantiated it.

You need to assign the mowers object to a value before you can use it.

// constructor for MowerWareHouse
public MowerWareHouse() {
  this.mowers = new ArrayList<>();
}

Again, this is just an assumption, I'd recommend replacing your screenshots with actual code.

zmehall
  • 557
  • 3
  • 13