import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;
public class SecondsTimer{
private ScheduledExecutorService timer;
private int seconds=0;
public SecondsTimer(){
long second=1000;
timer.scheduleAtFixedRate(new Runnable(){public void run(){seconds++;}},
second, second, TimeUnit.MILLISECONDS);
}
public int getSeconds(){return seconds;}
}
In the above code, I am attempting to create code to count seconds as they pass. I'm getting a runtime error, NullPointerException
for line 9. Is there an easier way to do this, or am I missing something obvious?