开发者

ObjectOutputStream .writeObject

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 = j开发者_高级运维TextField1.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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜