I made this program, it deals with classes and relationships, when I run this, it gives me the error "Exception in thread "main" java.lang.NullPointerException", my IDE doesn't detect any error in the coding, can anyone help me out, this is very annoying.
import java.util.Vector;
class Flight {
private String id;
private String destination;
private Time depart;
private Time arrival;
private Vector passengerList;
public Flight(String a, String b, Time c, Time d) {
id = a;
destination = b;
depart = c;
arrival = d;
}
public void addPassenger(Passenger a) {
passengerList.add(a);
}
public void printInfo() {
System.out.println("Id " + id);
System.out.println("Destination " + destination);
System.out.println("Depart " + depart.getHour() + " " + depart.getMinute());
System.out.println("Arrival " + arrival.getHour() + " " + arrival.getMinute());
System.out.println("Number of passengers " + passengerList.size());
}
}
class Time {
private int hour;
private int minute;
public Time(int a, int b) {
hour = a;
minute = b;
}
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
}
class Passenger {
private String name;
private int age;
public Passenger(String a, int b) {
name = a;
age = b;
}
}
class FlightTester {
public static void main(String[] args) {
Time dep = new Time(8, 10);
Time arr = new Time(9, 00);
Flight f = new Flight("PK-303", "Lahore", dep, arr);
Passenger psg1 = new Passenger("Umair", 30);
Passenger psg2 = new Passenger("Manzoor", 44);
f.addPassenger(psg1);
f.addPassenger(psg2);
f.printInfo();
}
}