BasicProgressBarUI.getPrefrerredSize的空指针异常

时间:2013-03-06 16:04:33

标签: java swing

执行SaveDialogsetVisible(true)行时,我收到以下异常。

当用户点击保存按钮时,此程序将启动。然后它会在尝试保存序列化对象数据时显示状态对话框。

public class SaveController implements ActionListener,Serializable{
    private JButton = new JButton("Save");
    public SaveController(){
         saveButton.addActionListener(this);
    }
    actionPerformed(ActionEvent ae){
       if(ae.getSource == saveButton){
             new saveDialog();
       }
    }
}

public saveDialog extends JDialog{
    public saveDialog(){

         SwingUtilites.invokeLater(new Runnabe()(
            public void run(){
                   // set up gui layout...add status lister
                   pack();
                   setVisible(true);// this is where it crashes
            }
         }
         SaveTask task = new SaveTask();
         task.addEventListener(this);
         task.execute()
     }
}

public class SaveTask extends SwingWorker<void,void>{

    public void doInBackground(){
        File f = new File("file");
        f.createNewFile();
        OutputStream file = new OutputStream("file");
        OutputStream buffer = new BufferedOutputStream(file);
        ObjectOutput output = new ObjectOutputStream(buffer);
        output.writeobject(object);
    }
}

0 个答案:

没有答案