Recently got back into using java again.
In the below code, if I use getProposal()
method inside the try catch block I get no problems however when trying to use the same method outside of the try catch block and in other methods (namely main) I get a null pointer exception (When calling the getProposal() method in the for loop).
public void grabProposals(String fname,Proposal[] proposals) {
try {
props = new File(fname);
sc = new Scanner(props).useDelimiter(",");
} catch (FileNotFoundException f) {
System.out.println(f);
}
int i = 0;
while (sc.hasNextLine()) {
if (i == proposals.length) break;
String prop = sc.nextLine();
String delimProp[] = prop.split(",");
String sName = null;
String pName = null;
try {
sName = delimProp[0];
pName = delimProp[1];
} catch (ArrayIndexOutOfBoundsException a) {
System.out.println(a);
}
proposals[i++] = new Proposal(pName,sName);
}
for (i = 0;i < proposals.length; i++) {
proposals[i].getProposal();
}
sc.close();
}