Null Pointer Exception even when array is initialized
<p>I am writing a program that takes in input various lecture requests that need to be scheduled.
The lectures have start time and an end time.
The requirement is to schedule the maximum number of lectures. (The algorithm is to schedule them by end time and select the non overlapping lectures--Greedy Strategy).
In order to do so I have a "lecture" class and a "LectureScheduling" class.
I create a input array (of lectures). Then I request the user to input the various requests.
However I am getting the error "Exception in thread "main" java.lang.NullPointerException".
Kindly help.
Thank you.
PS:
I have the error excatly at the line "input[i].time[0] = in.nextInt();"
The exact error is:
Exception in thread "main" java.lang.NullPointerException
at lecturescheduling.LectureScheduling.main(LectureScheduling.java:116)</p>

<p>// The lecture class.. time[0] is start time and time[1] is end time of the lecture</p>

<pre><code> class lecture{
     int[] time= new int[2];

     lecture (int a, int b){
          time[0]=a;
          time[1]=b;        
     }
 }
</code></pre>

<p>// Part of LectureScheduling Class</p>

<pre><code>public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.println("Input number of lectures ");
    int arraylength = in.nextInt();
    lecture [] input= new lecture[arraylength] ; 
    for (int i=0; i&lt;arraylength; i++){
        System.out.println("Input start time of lecture "+ i);
        input[i].time[0] = in.nextInt();        
        System.out.println("Input end time of lecture "+ i);
        input[i].time[1] = in.nextInt();        
        System.out.println();
    }
    input=SortByStartTime(input);
    input=CreateSchedule(input);
    PrintSchedule(input);
}
</code></pre>
