beshoyatef 0 Light Poster

I hide text inside image then i want to save the image wich contain message .
The problem is when i save image with JPEG it saved but give me exception :
java.lang.IllegalStateException: Output has not been set!
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:312)

and when i save image with any other formate the file saved but not contain the image and also give the same exception

why this ??
code:
---------

else if (e.getSource() == saveButton) {
                image = stegoPanel.getBufferedImage();
                imageData = getImageData(image);
                try {
                    img = hideing_text(imageData, str.getBytes("US-ASCII"), offset);
                    try {
                        saveBufferedImage = toImage(image.getWidth(), image.getHeight(), img);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                } catch (UnsupportedEncodingException ex) {
                    ex.printStackTrace();
                }
                int returnValue = fileChooser.showSaveDialog(TestImage.this);
                if (returnValue == JFileChooser.APPROVE_OPTION) {
                    try {
                        File selectedFile = fileChooser.getSelectedFile();
                        String fileName = selectedFile.getName();
                        String format = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()).toLowerCase();
                        stegoPanel.setBufferedImage(saveBufferedImage);
                        for (String name : ImageIO.getWriterFormatNames()) {
                            System.out.print("\nName: " + name + " format: " + format);
                            if (name.equals(format)) {
                                ImageIO.write(saveBufferedImage, format, selectedFile);
                                Iterator iter = ImageIO.getImageWritersByFormatName(format);
                                ImageWriter writer = (ImageWriter) iter.next();FileImageOutputStream(selectedFile);
                                ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(output);
                                writer.setOutput(imageOutputStream);
                 
                                writer.write(stegoPanel.getBufferedImage());
                 
                            } else {
                                System.out.println(" format is not supported");
                            }
                        }
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
            }

Thanks