currently getting the error "java.lang.NullPointerException: null" when attempting to add my Earthquake objects into my array list.
Note: I am using BlueJ to manually create and input values for my Earthquake(s).
Here is my earthquake class:
public class Earthquake {
// instance variables - replace the example below with your own
private double latitude;
private double longitude;
private double magnitude;
private int year;
public Earthquake(double latitude, double longitude, double magnitude, int year)
{
// initialise instance variables
this.longitude = longitude;
this.latitude = latitude;
this.magnitude = magnitude;
this.year = year;
}
public void storeLat (double longValue)
{
longitude = longValue;
}
public void storeLang (double latValue)
{
latitude = latValue;
}
public void storeMag (double magValue)
{
magnitude = magValue;
}
public void storeYear (int yearValue)
{
year = yearValue;
}
public int getYear ()
{
return year;
}
public double getMag ()
{
return magnitude;
}
public double getLat ()
{
return latitude;
}
public double getLong ()
{
return longitude;
}
}
And here is my Observatory class which is used to create the array list and add the Earthquake objects:
import java.util.ArrayList;
public class Obersvatory {
private String ObsName;
private String ObsCountry;
private int ObsStartYear;
private double ObsLocation;
private ArrayList<Earthquake> quakes;
public Obersvatory()
{
this.ObsName = ObsName;
this.ObsCountry = ObsCountry;
this.ObsStartYear = ObsStartYear;
this.ObsLocation = ObsLocation;
ArrayList<Earthquake> quakes = new ArrayList<Earthquake>();
}
public void addQuakes(Earthquake e)
{
quakes.add(e);
}
}
I'd be grateful on any fixes / tips :)