I have an ArrayList in a class and I want to reference it in another class, I've read that I can copy an ArrayList like this:
ArrayList<Persona> profesor= new ArrayList<>(persona);
However, every time I run it gives me a NullPointerException as if the ArrayList were referring to a valid object.
I am using it in this serializer method.
public void serializar() {
ArrayList<Contacto> contacto= new ArrayList<>(arreglo);
try {
FileOutputStream fos= new FileOutputStream("contactos.dat");
ObjectOutputStream oos= new ObjectOutputStream(fos);
if(oos != null)
{
oos.writeObject(contacto);
oos.close();
JOptionPane.showMessageDialog(null, "Contacto guardado");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Hubo un error en el proceso\n"
+ "Ha ocurrido el siguiente error: \n"+e);
}
}
}