Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need Help in IO Exception in method

s_pedros_pedro Posts: 8Member
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.