0

Maybe I'm just being blind or having a bad moment but for the life of me I can't manage to get this to work! It keeps throwing a null pointer exception.

Edit: The array's are initialised with normal string values, I've just not pasted it here.

ArrayList<String> starttime = new ArrayList();
ArrayList<String> endtime = new ArrayList();
ArrayList<Integer> bay = new ArrayList();

JLabel[] startTimes = new JLabel[starttime.size()-1];
JLabel[] endTimes = new JLabel[endtime.size()-1];
JLabel[] bayNo = new JLabel[bay.size()-1];

for (int i  = 0; i < starttime.size(); i++) {
    startTimes[i].setText("1");
    endTimes[i].setText("1");
    bayNo[i].setText("1");
    choices.add(startTimes[i]);
    choices.add(endTimes[i]);
    choices.add(bayNo[i]);
}
TheRapture87
  • 1,403
  • 3
  • 21
  • 31
  • See http://stackoverflow.com/questions/3426843/what-is-the-default-initialization-of-an-array-in-java – Oli Mar 24 '15 at 19:20

1 Answers1

0

You only create an array, but don't initialize the values in it. Create the labels in the array and everything should work.

for(int i = 0 ; i < starttime.size() ; i++){
    startTimes[i] = new JLable("1");
    ...
}