No enclosing instance of type E is accessible.

No enclosing instance of type E  is accessible.

静态方法(main)中调用内部类,会出现这样的问题;

学习了:https://www.cnblogs.com/runnigwolf/p/5570810.html

http://blog.csdn.net/sunny2038/article/details/6926079

public class SwingObserverExample {
    public static void main(String[] args) {
        JFrame jFrame = new JFrame();
        JButton jButton = new JButton("Should I do it?");
        jButton.addActionListener(new SwingObserverExample().new  AngelListener());
        jButton.addActionListener(new DevilListener());
        jFrame.getContentPane().add(jButton);
        jFrame.setVisible(true);
    }
    class AngelListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Don't do it!");
        }
        
    }
    static class DevilListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Just do it!");
        }
        
    }
    
}