I have a function that reads through a file, and gathers the results into an array list.
The array list looks like this (data)
[12, adam, 1993, 1234, bob, 1992]
I then need to load these details into new objects called patients. This is the current method I have so far for putting each separate array list item into its own patient, yet it keeps bugging me with an error saying I am passing in String String Int, and it needs to be a String.
s looks like this
12, adam, 1993
And this is the code
public void loadPatients()throws Exception
{
ArrayList<String> data = IO_Support.readData("PatientData.txt");
System.out.println(data);
for(String s : data)
{
Sytem.out.println(s);
patientList.add(new Patient(s));
}
}
Is there a way to push my array list result into a string for passing into the patient object, or should I use a different way to split the string results?
Read data looks like this
public static ArrayList<String> readData(String fileName) throws Exception
{
ArrayList<String> data = new ArrayList<String>();
BufferedReader in = new BufferedReader(new FileReader(fileName));
String temp = in.readLine();
while (temp != null)
{
data.add(temp);
temp = in.readLine();
}
in.close();
return data;
}
First thing, You are never adding your input to the ArrayList.. This while loop makes no sense.. It is just reading user input, and swallowing it on every occassion..
Plus, after seeing your exception, its sure that you are using a
1-arg constructorofPatient classwhich is not there.. There are only0-arg constructorand2-arg constructorinPatientclass.. You need to use them indeed.See this code in
loadPatientmethod.. You need to add a 1-arg constructor in your Patient class to get it compiled..So, in your Patient class, add: –
this.sis the instance variable to storesthat you passed..