public void populatePrizeArraylist()
{
ArrayList <Prize> prizeArrayList = new ArrayList <Prize>();
// The name of the file which we will read from
File filename = new File("prizes.txt");
try
{
// Prepare to read from the file, using a Scanner object
FileReader inputFile = new FileReader(filename);
Scanner parser = new Scanner(inputFile);
// Read each line until end of file is reached
while (parser.hasNextLine())
{
// Read an entire line, which contains all the details for 1 prize
String readFile = parser.nextLine();
String delimiter = ",";
String[] fileList = readFile.trim().split(delimiter);
Prize newPrize = new Prize();
newPrize.setPrizeName(fileList[0]);
newPrize.setPrizeWorth(Integer.parseInt(fileList[1]));
newPrize.setPrizeCost(Integer.parseInt(fileList[2]));
this.prizeArrayList.add(newPrize);
}
}
}
What am I doing wrong here? I have created a new ArrayList then a new object and set some values to the name variable of that object but when I try to add that object to my arraylist i get a null point exception error
setGoodName()method on theArrayListinstead of your objectnewItem