I'm sorry I am very new to programming and have encountered what I hope is a simple problem to solve. I'll put my code in here and explain what I am trying to do below.
public class main {
static ArrayList<Interpreter> ints1;
static ArrayList<Customer> custs1;
static MainFunctions mainF;
static { //Static blocks execute first - and are great for initializing data!
ArrayListPopulator ALP1 = new ArrayListPopulator();
ints1 = ALP1.populateALints1(); // error occurs on this method call.
custs1 = ALP1.populateALcusts1();
mainF = new MainFunctions(ints1, custs1);
}
public static void main(String[] args) {
mainF.findNearestInterp("Frank");
}
}
ArrayList Populator:
import java.util.ArrayList;
public class ArrayListPopulator {
private ArrayList<Interpreter> ints1ToGo;
private ArrayList<Customer> custs1ToGo;
public ArrayList<Interpreter> populateALints1() {
//Format is "String pName, int pAge, String PGender,
// int pSignLevel, boolean pDeafBlindExp, double pLatitude, double pLongitude, String pTown"
//Gender must be "Male"||"Female"
//In future this could be done by scanning a local config text file. Wish that I knew that stuff :l
Interpreter Elliott = new Interpreter("Elliott", 23, "Male", 6, true, 52.098049, 0.277860, "Linton");
ints1ToGo.add(Elliott); //error occurs here.
Interpreter Sarah = new Interpreter("Sarah", 20, "Female", 3, true, 52.209950, 0.137774, "Cambridge");
ints1ToGo.add(Sarah);
Interpreter Argibarge = new Interpreter("Argibarge", 42, "Male", 3, false, 52.599199, -0.264226, "Peterborough");
ints1ToGo.add(Argibarge);
Interpreter Bruce = new Interpreter("Bruce", 30, "Male", 2, false, 50.717527, -3.540192, "Exeter");
ints1ToGo.add(Bruce);
Interpreter Medusa = new Interpreter("Medusa", 1009, "Female", 4, false, 55.867795, -4.267566, "Glasgow");
ints1ToGo.add(Medusa);
return ints1ToGo;
}
public ArrayList<Customer> populateALcusts1() {
//Format is "String pName, int pAge, String PGender,
//boolean pDeafBlind, double pLatitude, double pLongitude, String pTown"
//Gender must be "Male"||"Female"
//In future this could be done by scanning a local config text file. Wish that I knew that stuff :l
Customer Frank = new Customer("Frank", 30, "Male", false, 56.113482, -3.934635, "Stirling");
custs1ToGo.add(Frank);
Customer Eleanor = new Customer("Eleanor", 23, "Female", true, 52.622439, 1.281124, "Norwich");
custs1ToGo.add(Eleanor);
Customer Pacha = new Customer("Pacha", 43, "Male", false, 52.397273, -0.727392, "Kettering");
custs1ToGo.add(Pacha);
Customer Roy = new Customer("Roy", 69, "Male", false, 51.746940, -1.257345, "Oxford");
custs1ToGo.add(Roy);
Customer Jenette = new Customer("Jenette", 16, "Male", false, 51.871877, 0.357845, "Great Dunmow");
custs1ToGo.add(Jenette);
return custs1ToGo;
}
}
Error Message at runtime:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at ArrayListPopulator.populateALints1(ArrayListPopulator.java:16)
at main.<clinit>(main.java:23)
The thing I am most new to in this code is the static {} block to initialize my main ArrayLists of data from the data stored in the ArrayListPopulator class. It would appear that I am not initializing the ArrayList properly, or adding the elements properly, or I'm not assigning the reference variable properly.
Thank you so much for any help!