Working with GUI in Java I can't save(serialize) pattern to a file

0

I want to save a pattern of my GUI BeatBox. I'm having a trouble to save it >to a file. Error is popping out. The code compiles but it doesn't do what i want - does not save to a file. button to be clicked on my GUI work:

 JButton serializeIt = new JButton("serializeIt");
            serializeIt.addActionListener(new MySendListener());
            buttonBox.add(serializeIt); 

the inner class of BeatBox class that supposed to do the work when button is clicked:

 public class MySendListener implements ActionListener {
            public void actionPerformed(ActionEvent a) {
                boolean[] checkboxState = new boolean[256];
                for (int i = 0; i < 256; i++) {
                    JCheckBox check = (JCheckBox) checkboxList.get(i);
                    if (check.isSelected()) {
                        checkboxState[i] = true;
                    }
                }
                try {
                    FileOutputStream fileStream = new FileOutputStream(new File("Checkbox.ser"));
                    ObjectOutputStream os = new ObjectOutputStream(fileStream);
                    os.writeObject(checkboxState);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }

When running GUI without pressing the button

WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

When pressing the button (to much to post everything,I just post two lines >of 9 that I got)

java.io.FileNotFoundException: Checkbox.ser (The system cannot find the file specified) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

java
user-interface

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0