Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need Help in IO Exception in method Posted by s_pedro on 21 Jan 2011 at 4:00 AM
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");
writetoFile(patient); //giving an error
}
if (source == uadd)
{
Patient patient = new Patient(...));
printPatients(patient);
writetoFile(patient); //giving an error

}
}

//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:\Users\Pedro Quintas\Documents\Documents and Work\Escola\Computer Science\Programs\Dossier\AddPatient.java:362: unreported exception java.io.IOException; must be caught or declared to be thrown

Please tell me whats wrong,
thanks



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.