Search code examples
javatimerargumentsactionlistenerschedule

Constructor cannot be applied to given types Timer


It says

constructor Timer in class Timer cannot be applied to given types.
required:int, ActionListener.
found:no arguments.
reason: actual and formal argument lists differ in length.

and

cannot find symbol. symbol: method scheduleAtFixedRate

private void initBoard() {
  addKeyListener(new TAdapter());
  setFocusable(true);

  bricks = new Brick[N_OF_BRICKS];
  setDoubleBuffered(true);
  timer = new Timer();
  timer.scheduleAtFixedRate(new ScheduleTask(), DELAY, PERIOD);
}

Solution

  • It seems like you imported the Timer class from javax.swing.Timer instead of java.util.Timer.

    You need the following statement in the beginning of your file:

    import java.util.Timer;