Hi everyone
I am fairly new to java and ony know the reall basics (if statements, while loops) that kind of stuff however I have started to dabble in the crazy world of lists and collections.... I am using BlueJ (the latest version) and before you say it.......... I know everyone has told me this is not to good, however it is what the uni force use to use...;)
Any way i am writing this code just to add daysOfTheweek to an arraylist and then use another method to print to terminal;
import java.util.*;
public class Collections
{
ArrayList DaysOfTheweek;
public Collections() {
ArrayList DaysOfTheweek = new ArrayList();
}
public void addDays() {
DaysOfTheweek.add("Monday");
DaysOfTheweek.add("Tuesday");
DaysOfTheweek.add("Wednesday");
DaysOfTheweek.add("Thursday");
DaysOfTheweek.add("friday");
DaysOfTheweek.add("Saturday");
DaysOfTheweek.add("Sunday");
}
public void printDays() {
int i = 0;
while (i < DaysOfTheweek.size()-1) {
System.out.println(""+DaysOfTheweek.get(i));
i++;
}
}
}
The problem I keep getting is a null pointer execption?? I know this means it is trying to access an empty part of the list. I just cant see where I have gone wrong so PLEASE if anyone can help me out of this it would be much appreciated :)
THANKS !!!!