我一直在尝试运行多线程,但我得到的错误可以任何一个帮助我,我一直在改变这个洞很多,但我还没有找到方法解决这个问题:“不能使用类型为programa4的封闭实例,必须使用类型为programa4的封闭实例限定分配(egxnew A(),其中x是programa4的一个实例)。” 谢谢大家。没有可以访问类型的封闭实例。错误和任何机构可以帮助我一直在尝试改变一切,但没有结果
public class programa4 {
public static void main(String[] args) {
int t=Integer.parseInt(args[0]);
int x=1;
String z=args[1];
while(x<=t){
System.out.println("Iniciando hilo "+x);
new hilo(z).start();
x=x+1;
}
}
class hilo extends Thread{
int num;
String z;
hilo(String z){
this.num=Integer.parseInt(z);
}
public void run() {
int t=1;
while(t<=num){
System.out.println("Generando iteracion: "+ t);
double x=Math.random()*10;
System.out.println("Esperando "+ x +" segundos");
try {
Thread.sleep((long)x*1000);
System.out.println("Iteracion terminada");
} catch (InterruptedException e) {
System.out.println("Se interrumpio.");
}
t=t+1;
}
System.out.println("Terminado hilo.");
}
}
}
'static class hilo extends Thread' - add ** static **。 – OldCurmudgeon
可能重复的[Java - 没有封闭的Foo类型的实例可以访问](http://stackoverflow.com/questions/9560600/java-no-enclosing-instance-of-type-foo-is-accessible) – Raedwald