Need Help in IO Exception in method

So i am trying to implement a method to write from an object into a Data stream. I he to write the algorithm in a method because i am using GUIs. Here is the code:

/* ACTION PERFORMED**/
public void actionPerformed(ActionEvent evt){

Object source = evt.getSource();

if (source == add)
{
String mothername = " ";
String fathername = " ";
String motherphone = " ";
String fatherphone = " ";
Patient patient = new Patient(...));
printPatients(patient);
System.out.println("past printing patient");
[color=Blue]writetoFile(patient);[/color] [color=Green]//giving an error [/color]
}
if (source == uadd)
{
Patient patient = new Patient(...));
printPatients(patient);
[color=Blue]writetoFile(patient);[/color] [color=Green]//giving an error [/color]

}
}

//This is the method I am trying to call
public static void writetoFile(Patient p) throws IOException
{
RandomAccessFile inout = new RandomAccessFile("PatientsInfo.dat", "rw");

inout.seek(inout.length());

inout.writeUTF(p.getName());
inout.writeUTF(p.getAge());
inout.writeUTF(p.getGender());
inout.writeUTF(p.getSiblings());
inout.writeUTF(p.getID());
inout.writeUTF(p.getNationality());
inout.writeUTF(p.getCivilStatus());
inout.writeUTF(p.getProfession());
inout.writeUTF(p.getPhone1());
inout.writeUTF(p.getPhone2());
inout.writeUTF(p.getEmail());
inout.writeUTF(p.getMotherName());
inout.writeUTF(p.getFatherName());
inout.writeUTF(p.getMotherPhone());
inout.writeUTF(p.getFatherPhone());
inout.writeUTF(p.getMedication());
inout.writeUTF(p.getDoctorsName());
inout.writeUTF(p.getFrequency());
inout.writeUTF(p.getPrice());

System.out.println("names and sentinel value sent to file Countries.dat");
inout.close();
}

//The error is in the two blue lines, and the error it shows is:

Error: C:UsersPedro QuintasDocumentsDocuments and WorkEscolaComputer ScienceProgramsDossierAddPatient.java:362: unreported exception java.io.IOException; must be caught or declared to be thrown

Please tell me whats wrong,
thanks
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories