我想使用线程谁能告诉我什么是在下面的代码中的错误。我主要获得NullPointerException
。如何获取对象内的对象?
public class threadtest implements Runnable {
Thread t;
public threadtest(String name) {
Thread t = new Thread(name);
}
public void run() {
for(int i = 0; i <= 10; i++) {
try {
Thread.sleep(1000);
}
catch(Exception e) {
System.out.println(e);
}
}
}
public static void main(String args[]) {
threadtest ob = new threadtest("satheesh");
ob.t.start();
}
}
错误的是代码的格式。 – Istao 2011-01-26 13:04:38