2017-09-13 41 views
1

我不明白什麼是錯在此代碼:無法執行我的定時器

import java.util.*; 

public class Timer { 

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

這是我第一次在Java中使用定時器和它說

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

我錯過了什麼?

回答

2

您正在創建類Timer的實例。您的班級計時器沒有方法計劃。如果你要使用this定時器,我建議命名你的類別的

+0

我的壞,我沒有看到......非常感謝你 – dulindraxe

2

爲了避免使用相同的類名衝突,你應該使用完整的軟件包名稱或完全合格的名稱爲:

java.util.Timer timer = new java.util.Timer(); 
timer.schedule(new Run(), 0, 5000); 
相關問題