views:

56

answers:

1

hey i have some problems with this code... This is a JDialogForm in which I have jTextField and button. I want to save data from this Jtextfield when i click button to use it in another window but i don't know why it doesn't work. I always get Exception ek and the message i have put there.

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    String sciezka = jTextField1.getText();
    if (sciezka.length() > 0)
    {
      Zmienne_pomocnicze zp = new Zmienne_pomocnicze();
      zp.setPrzechowaj(sciezka);
       try {
       ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream("danebaza"));
       oos.writeObject(zp);

       oos.close();


   } catch(Exception ek) {
       JOptionPane.showMessageDialog(null, "Nie mozna pobrac nazwy_przedmiotu: " + ek);
     }
   }
    this.setVisible(false);
}                    

where class Zmienne_pomocnicze looks like this

public class Zmienne_pomocnicze {

    public String n;


    public void setPrzechowaj (String neew){
        n = neew;

    } public String getPrzechowaj () {
        return n; 
    } 
}

i guess the problem is with oos.writeObject(zp); but i don't know why.

+2  A: 

Your class Zmienne_pomocnicze is not Serializable. You must declare it serializable in order to write it into an object output stream (and make sure all its data members are serializable as well, though in your particular case this is true).

Eyal Schneider
thanks now it works :)
bigbluedragon