Java -The method sleep(int) is undefined for the type Thread

后端 未结 7 2047
南方客
南方客 2020-12-18 14:46

I\'m getting an error: The method sleep(int) is undefined for the type Thread. I thought the sleep method is in the Thread class in Java.

import java.util.Ra         


        
7条回答
  •  一整个雨季
    2020-12-18 15:25

    You implemented your own class called Thread and try to call sleep on it, which fails, cause sleep is undefined in your class. Your class basically shadows java's Thread class.

    Call your class differently (ie. MyThread or even better MyRunnable, as noted by owlstead) or call java.lang.Thread.sleep() directly.

提交回复
热议问题