I have a static arraylist defined in my loginactivity class.
private static ArrayList<LatLng> userCoordinates;
// Removed some code for ease of reading but the contents of the list are defined and set here:
ArrayList<LatLng> coords = new ArrayList<>();
for (String lat: lats) {
for (String lng: lngs) {
double a = Double.parseDouble(lat);
double b = Double.parseDouble(lng);
LatLng latLng = new LatLng(a,b);
coords.add(latLng);
break;
}
}
setCoordinates(coords);
// Getter & Setter
private void setCoordinates(ArrayList<LatLng> coordinates) {
userCoordinates = coordinates;
}
public static ArrayList<LatLng> getCoordinates() {
return userCoordinates;
}
However when I attempt to access this from another class and print it in the onCreate() method:
private ArrayList<LatLng> userCoordinates = LoginActivity.getCoordinates();
//In onCreate()
System.out.println(userCoordinates.toString());
I get the error: Attempt to invoke virtual method 'java.lang.String java.util.ArrayList.toString()' on a null object reference