Buongiorno,

Sto facendo un programma di registrazione e log in in una semplice interfaccia grafica accedendo a un file "Dati.dat".
Ho letto che l'errore "AWT-EventQueue-0" java.lang.NullPointerException, sorge alla chiamata di un metodo a un oggetto non ancora inizializzato.
Praticamente succede questo: quando inserisco i dati (username,password,name,surname), creo un oggetto Registered acquisendo ciò che i JTextField contengono.
Poi richiamo una funzione che sfruttando l'oggetto ObjectOutputStream li scrive nel file "Dati.dat"

Scusate se non sono stato chiaro ...grazie per la lettura

codice:
bRegistration.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    if (pRegistration.getText().equals(rpRegistration.getText())) {
                        Registered person=new Registered (nRegistration.getText(),
                                                            sRegistration.getText(),
                                                            uRegistration.getText(),
                                                            pRegistration.getText());
                        
                        person.registration(person);
                    } else {
                        JFrame error=new JFrame ("Error");
                    }
                }
            });

public class Registered implements Serializable {
    private String name;
    private String surname;
    private String username;
    private String password;
    private FileOutputStream fout;
    private FileInputStream fin;
    private ObjectOutputStream oout;
    private ObjectInputStream oin;
    
    public Registered () {
        this.name="";
        this.surname="";
        this.username="";
        this.password="";
        
        try {
            fout=new FileOutputStream("Dati.dat");
            fin=new FileInputStream ("Dati.dat");
            
            oout=new ObjectOutputStream (fout);
            oin=new ObjectInputStream (fin);
        } catch (FileNotFoundException e) {
            JFrame error=new JFrame ("Error");
        } catch (IOException e) {
            JFrame error=new JFrame ("Error");
        }
    }
    
    public Registered (String name,String surname,String username,String password) {
        this.name=name;
        this.surname=surname;
        this.username=username;
        this.password=password;
    }
public void registration (Registered person) {
        try {
            oout.writeObject(person);
        } catch (IOException e) {
            JFrame error=new JFrame ("Error");
            [...]
        }
    }