您的位置:首页 > 其它

在静态方法中实例化非静态类内部类时报错

2016-05-09 22:22 507 查看
在main函数中实例化内部类时会报错:

No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).

说没有可用的实例,代码:

public class Test {

public static void main(String[] args){

TimePinter listener = new TimePinter();
Timer timer = new Timer(10000, listener);
JOptionPane.showConfirmDialog(null, "Quit program");
<span style="white-space:pre">		</span>System.exit(0);

}

class TimePinter implements ActionListener{

@Override
public void actionPerformed(ActionEvent e) {
Date now = new Date();
System.out.println("The current time is "+now);
Toolkit.getDefaultToolkit().beep();
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: