user7024314
user7024314

Reputation:

Unable to execute my Timer

I can't understand what is wrong in this code:

import java.util.*;

public class Timer {

    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new Run(), 0, 5000);
    }
}

It's the first time I use Timer in Java and it says

 error: cannot find symbol
 timer.schedule(new Run(), 0, 5000);
      ^ 
 symbol: method schedule(new Run(), int, int)
 location: variable timer of type Timer

What am I missing?

Upvotes: 1

Views: 117

Answers (2)

Naman
Naman

Reputation: 31858

To avoid using same class name conflicts, you should use the complete package name or the fully qualified name as:

java.util.Timer timer = new java.util.Timer();
timer.schedule(new Run(), 0, 5000);

Upvotes: 1

Tyler
Tyler

Reputation: 955

You are creating an instance of your class Timer. Your class Timer does not have a method schedule. If you are trying to use this timer, I suggest naming your class something else

Upvotes: 1

Related Questions