class java{
public static void main(String args[]){
Thread thisthread=Thread.currentThread();
for(int counter=0;counter<10;counter+=2){
System.out.println(counter);
Thread.sleep(1000);
}
}
}
public static void main(String args[]){
Thread thisthread=Thread.currentThread();
for(int counter=0;counter<10;counter+=2){
System.out.println(counter);
Thread.sleep(1000);
}
}
}
public static void main(String args[]){
Thread thisthread=Thread.currentThread();
for(int counter=0;counter <10;counter+=2){
System.out.println(counter);
try{
thisthread.sleep(1000);
}
catch(Exception e){
}}
}
}
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}加上try/catch就行了
无法访问 Thread
错误的类文件:.\Thread
文件不包含类Thread
请删除该文件或确保该文件位于正确的类路径目录中
这个是错误信息
当前没有线程在运行所以没有找到吧????????
如果使用Eclipse等开发工具的话,去查下CLASSPATH环境变量有没有设置正确,
如果直接使用"java 类名"方式来运行的话,注意你的命令行是怎么写的~~
public class Testa { public static void main(String args[]) {
Thread thisthread = Thread.currentThread();
for (int counter = 0; counter < 10; counter += 2) {
System.out.println(counter);
try {
Thread.sleep(1000);
} catch (InterruptedException e) { e.printStackTrace();
}
}
}
}
public static void main(String args[])throws Exception{
Thread thisthread=Thread.currentThread();
for(int counter=0;counter <10;counter+=2){
System.out.println(counter);
Thread.sleep(1000);
}
}
}
上面的代码在我机上运行没有问题,你试一下!
如果还不行,那真的可能就是你机的问题了!
public static void main(String args[])throws Exception{
Thread thisthread=Thread.currentThread();
for(int counter=0;counter <10;counter+=2){
System.out.println(counter);
Thread.sleep(1000);
}
}
}
上面的代码在我机上运行没有问题,你试一下!
如果还不行,那真的可能就是你机的问题了!
位不妨试试加一句 import java.lang.*;
看看错误还是一样的吗?
呵呵
其实上面的没有问题
你用编译环境的,还是文本的,
呵呵
public class java{
public static void main(String args[]){
Thread thisthread=Thread.currentThread();
for(int counter=0;counter <10;counter+=2){
System.out.println(counter);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
这个完全不搭尬啊线程是睡眠不需要try catch的啊主要还是Import thread线程的那个包吧