以下代码给了我 NullPointerException。
class MT extends Thread{
public void run(){
}
}
public class ThreadGroupDemo{
public static void main(String[] args) throws InterruptedException{
MT t = new MT();
t.start();
Thread.sleep(5000);
System.out.println(t.getName());
//^^^^This line gives the thread name
System.out.println(t.getThreadGroup().getName());
//^^^^This line is giving me NullPointerException
}
}
此代码的最后一行给出 NullPointerException。