SportLottery snp=new SportLottery();nullPointer Exception 一般因为对象没有初始化。

解决方案 »

  1.   

    C:\j2sdk141\bin\javaw.exe -classpath C:\j2sdk141\jre\lib\charsets.jar;C:\j2sdk141\jre\lib\jaws.jar;C:\j2sdk141\jre\lib\jce.jar;C:\j2sdk141\jre\lib\jsse.jar;C:\j2sdk141\jre\lib\rt.jar;C:\j2sdk141\jre\lib\sunrsasign.jar;C:\j2sdk141\jre\lib\ext\dnsns.jar;C:\
    java.lang.OutOfMemoryError
    Exception in thread "main" Process terminated with exit code 1
    改过来以后,又出现了这样的提示。连程序都不运行了,也看不见窗体。
      

  2.   

    public class ButtonPanel extends JPanel implements ActionListener {
        SportLottery snp;
        JButton Random = new JButton("Random");
      SportLottery sl;
        public ButtonPanel (SportLottery _sl) {
            sl=_sl;
            Random.addActionListener(this);
            setLayout(new BorderLayout());
            add(Random, BorderLayout.NORTH);
        }    public void actionPerformed(ActionEvent e) {
            Object source;
            source = e.getSource();
            if (source == Random) {
                sl.update();         //**
            }
        }
    }
    并且:SportLottery中:
    ButtonPanel bp = new ButtonPanel(this);