Q:

set a timer in java have compile time error

compile time error: 
constructor Timer in class Timer cannot be applied to given types
Timer timer = new Timer();
how can this be solved? 
Here is my current code:
import java.util. TimerTask;
import javax.swing. Timer;

public class testNotification{

    public static void main(String args[]) {

        Timer timer = new Timer();

        timer.schedule(new TimerTask() {

            public void run() {
            }

        }, 2 * 60 * 1000);
    }
}

A:

Looks like you're using a javax.swing. Timer, which needs a long and an ActionListener as constructor arguments and does not have a schedule method.  It seems that you meant to use a java.util. Timer instead based on the code you provided. 
So change import javax.swing. Timer to import java.util. Timer and you should be fine. 
The schedule method that you use will execute the task just once.  If you want the task to be executed multiple times, you should consider using either this schedule method or the scheduleAtFixedRate method depending on your needs.