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

后端 未结 7 2055
南方客
南方客 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:26

    It's not in your Thread class.

    Since you named your class Thread, that's where Java will look for Thread.sleep. If you want the function that's built into Java, try java.lang.Thread.sleep(time);.

提交回复
热议问题