I am trying to add a class to an array and I get Exception in thread "main" java.lang.NullPointerException in my addAstronaut
class.
package gov.nasa.spacevehicles;
import gov.nasa.personnel.Astronaut;
public class SpaceStation {
//private members
private String name;
private double stationWeight;
private double altitude;
private Object[] Astronauts;
private int totalAstronauts;
//overloaded constructor
public SpaceStation(String name, double weight) {
int altitude = 0;
int totalAstronauts = 0;
}
//method
public void addAstronaut(String name, double height, double weight) {
Astronauts[0] = new Astronaut(); // Exception in thread
Astronauts[1] = new Astronaut();
Astronauts[2] = new Astronaut();
stationWeight = stationWeight + weight;
}