I keep on getting a null pointer exception when i invoke the add method the code seems fine but i dont know what is wrong.
public class CarRunner {
public static void main(String[] args) {
TrafficLight light = new TrafficLight();
RoadRunnable run1 = new RoadRunnable(1,light);
String car="car";
for (int i =0;i<100;i++)
{
car="car"+i;
run1.add(car);
}
Thread traffic1 = new Thread(run1);
traffic1.start();
}
}
public class RoadRunnable implements Runnable{
private LinkedList<String> queue;
private int number;
private TrafficLight light;
public RoadRunnable(int roadNumber, TrafficLight aLight)
{
number = roadNumber;
light = aLight;
}
public void add(String car)
{
queue.add(car);
}
}